Reputation: 873
I have a tree of categories in my database. I also have a table of items associated with the tree by a category id.
Now, I want to list all items in a specific category and its children and their children, etc...
For now, I proceed this way:
I think this way cause the query to be very slow and very long if I have a lot of categories. A search can be in 100 categories sometimes.
Is there a better practice?
Upvotes: 1
Views: 361
Reputation: 4215
From gugl on "storing tree in relational database": http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
+1 about
EXPLAIN select * from table
that will help you to see bottlenecks.
Also try instead of
column1 = 1 or column1 = 2
something like:
column1 in (1, 2)
But anyway without indexes it wouldn`t help.
Upvotes: 1