在sqlite中进行递归计算的替代方法? [英] Alternative for recursively making recursive calculations in sqlite?

查看:85
本文介绍了在sqlite中进行递归计算的替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为iPhone设计一个项目,该项目需要访问存储在本地sqlite数据库中的大量分层数据.一种更常见的操作是计算汇总状态字段.现在,我通过遍历该项目的所有后代(可以是1到n层深的任何地方)来做到这一点.但是,这最终需要很多sql调用.iPhone上的每个sqlite调用大约需要250毫秒才能完成,最终,这总共需要大约7.7秒的处理时间.有没有人建议在不到O(n)的时间内做类似的事情?我认为问题的根源在于发出的大量SQL调用,所以这就是我要减少的问题.

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.

推荐答案

您需要其他表组织.看看在MySQL中管理分层数据或在乔·塞科(Joe Celko)的书.

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

这篇关于在sqlite中进行递归计算的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆