English 中文(简体)
结 论 以千万万分之十计的成绩
原标题:Closure table Root Nodes Query performance with 10s of millions of nodes

目前,我有一个分级数据关闭表,有500万分点,导致关闭表上约7 500万分。 由于关闭表的尺寸,利用SqLite 我的询问时间正在成指数上升。

CREATE TABLE `Closure` (`Ancestor` INTEGER NOT NULL ,`Descendant` INTEGER NOT NULL ,`Depth` INTEGER, PRIMARY KEY (`Ancestor`,`Descendant`) )
CREATE INDEX `Closure_AncestorDescendant` ON `Closure` (`Ancestor` ASC, `Descendant` ASC);
CREATE INDEX `Closure_DescendantAncestor` ON `Closure` (`Descendant` ASC, `Ancestor` ASC);
CREATE TABLE `Nodes` (`Node` INTEGER PRIMARY KEY NOT NULL, `Root` BOOLEAN NOT NULL, `Descendants` INTEGER NOT NULL);

我问,找到根基的节点需要20分钟左右,尽管只有大约5个或6个节点会问。

SELECT `Closure`.`Ancestor` FROM `Closure` 
LEFT OUTER JOIN `Closure` AS `Anc` ON `Anc`.`Descendant` = `Closure`.`Descendant` 
AND `Anc`.`Ancestor` <> `Closure`.`Ancestor` WHERE `Anc`.`Ancestor` IS NULL;

20分钟后,如果 no子是根基并修改了<条码>,则Im 储存一个毛子。 我对重复数据并不感到非常高兴,但我的问答时间目前是每个问询单位数毫米秒。

我也有许多问询,需要了解某一 no子的多少后代(主要是如果 Des子和gt子;1)知道该目标是否能够在树眼中实现虚拟化/扩大。 我每次都问这个问题,但是,在像我这样具有指数的巨型数据库中,问询似乎要长(超过1秒),因此,我也将其减到<条码>第。 令人不舒服的是我想要避免的另一个重复数据。

我使用的询问如下。 如果任何人能够解释如何提高这一业绩(我认为我已经有了从Ancestor开始的指数),我将不胜感谢。

SELECT COUNT(*) FROM `Closure` WHERE `Ancestor`=@Node
最佳回答

Does the version of SQLite you re developing on support Foreign Keys? If so, your closure table design should have a FK referencing the hierarchy table you re supporting with the closure table. In TSQL:

constraint fk_a FOREIGN KEY (ancestor) REFERENCES <hierarchy_tablename> (nodeid)
constraint fk_d FOREIGN KEY (descendant) REFERENCES <hierarchy_tablename> (nodeid)

你们不得不看看一下相关的Kallite syntax, s。

由于你已经保持了深厚的领域,即后代与祖先之间的距离,你可以利用这个领域来说明某一天是否有孩子。

select top 1  EXPANDABLE  as whatever
from closure C
where exists (select ancestor from closure where depth > 0 and ancestor = C.ancestor)
and ancestor = @Node

不管你的关闭表的规模如何,这应当迅速回头。 如果你从那里获得一个空套,那么,由于你没有孩子,你给你的 no子不能再扩大。 极端主义分子一旦发现符合你的标准的某例,就立即返回,而你只接上头一例,你就不把一行 return回过来。

关于改进寻找根源的工作,可尝试如下。 它是我用来寻找根源的,但我的关闭表只有约200 000人。 我比较了每项计划,并比较了你的代码使用哈希语,这可能会因处理器对装置的要求而影响其性能(这里假定KQite是Pi/iPad,或某些类型的小配器)。 下文使用较少的加工力,而且从计划中的指数中读得更多,并利用等级与封闭表的关系。 我不能肯定,这将改善你的业绩,但值得一击。

select a.node_name, a.node_id
from test.hier a left outer join 
                 (select coo.descendant /* coo = CHILD OF OTHER */
                  from test.closure_tree coo right outer join test.closure_tree ro
                        on coo.ancestor <> ro.descendant /* ignore its self reference */
                        and coo.descendant = ro.descendant /* belongs to another node besides itself */)lo 
    on a.node_id = lo.descendant
where lo.descendant is null
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签