Store multidimensional array in database: relational or multidimensional?

后端 未结 6 1761
栀梦
栀梦 2021-02-14 02:14

I have read numerous posts along the lines of multidimensional to single dimension, multidimensional database, and so on, but none of the answers helped. I did

6条回答
  •  [愿得一人]
    2021-02-14 02:25

    You absolutely can do that (if I've read your question correctly).

    Depending on your RDBMS you might have to choose a different way.

    Your basic structure of having a parent is correct.

    SQL Server use recursive common table expression (CTE) to anchor the start and work down

    https://technet.microsoft.com/en-us/library/ms186243(v=sql.105).aspx

    Edit: For Linux use the same in PostgreSQL https://www.postgresql.org/docs/current/static/queries-with.html

    Oracle has a different approach, though I think you might be able to use the CTE as well.

    https://oracle-base.com/articles/misc/hierarchical-queries

    For 100k rows I don't imagine performance will be an issue, though I'd still index PK & FK because that's the right thing to do. If you're really concerned about speed then reading it into memory and building a hash table of linked lists might work.

    Pros & cons - it pretty much comes down to readability and suitability for your RDBMS.

    It's an already solved problem (again, assuming I've not missed anything) so you'll be fine.

提交回复
热议问题