Alternative for recursively making recursive calculations in sqlite?

☆樱花仙子☆ 提交于 2020-01-02 05:40:29

问题


I am currently working on a project for the iPhone that requires accessing a large amount of hierarchical data stored in a local sqlite database. One of the more common operations is calculating a rollup status field. Right now, I'm doing that by recursing through all the descendants of that item (which can be anywhere from 1 to n levels deep). However, this ends up requiring a LOT of sql calls. Each sqlite call on an iPhone takes around 250ms to complete, and in the end this adds up to around 7.7 seconds of processing time. Does anyone have any suggestions of doing something like this in less than O(n) time? I think the root of the problem is the sheer number of sql calls being made, so that's what I'm looking to reduce.


回答1:


You need a different table organization. Have a look at Managing Hierarchical Data in MySQL or at Joe Celko's book.



来源:https://stackoverflow.com/questions/832106/alternative-for-recursively-making-recursive-calculations-in-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!