SQL Parent/Child recursive call or union?

后端 未结 5 982
有刺的猬
有刺的猬 2021-02-10 11:04

I can\'t seem to find a relevant example out there.

I\'m trying to return a sub-set of a table, and for each row in that table, I want to check how many children it has,

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 11:37

    Did you ever try to add an index to parent id for MySQL. I'm pretty sure the exection times will improve vastly. Haven't tested but I would say that MySQL goes through all rows to determine the count. Meaning that it does 10 - 40 billion (number of rows in the table * 10000) lookups in those 59 seconds.

    Assume that SQL Server and Oracle create an index on the fly. If they do, it would be only 1 to 4 million.

提交回复
热议问题