English 中文(简体)
Joining Onto CTE 业绩
原标题:Joining Onto CTE Performance

我有一个储存程序,利用共同的表格表达方式,形成一种等级的 path子(因此,它能够展示出像父母Menu->Sub Menu-> Sub Menu->......)

对于我想要利用这一信息来说,它发挥了巨大作用,问题在于将我从休庭的智囊团获得的信息纳入我真正想要的信息。 我从我的数据中向国家情报和安全局做一个内部的Join,并走出了等级线。 对于那些返回约300个牢房的人,所储存的程序平均为15-20秒。

当我把考试和测验的结果列入一个温度表并在此基础上加入时,这一程序就算不到第二个。

我很想知道,为什么要这么长的时间才加入专门委员会,或者如果我以某种方式误用了专门委员会。

** 这主要是储存程序。

With Hierarchical_Path (Menu_ID, Parent_ID, Path) 

As
(
Select
    EM.Menu_Id, Parent_ID, 
            Convert(varchar(max), 
            EM.Description) as Path
From
    Menu EM
Where
--EM.Topic_No is null
    EM.Parent_ID = 0 and EM.Disabled = 0
Union All
Select  
    EM.Menu_ID,  
            EM.Parent_ID, 
            Convert(Varchar(max),E.Path +   ->   + EM.Description) as Path
From
    Menu EM
Inner Join
    Hierarchical_Path E
On
    EM.Parent_ID = E.Menu_ID    
)

SELECT distinct   
    EM.Description
    ,EMS.Path
FROM
    dbo.Menu em
INNER JOIN
    Hierarchical_Path EMS
ON
    EMS.Menu_ID = em.Menu_Id
    2 more INNER JOINs
    2 Left Joins
    WHERE Clause

当我接受这样的询问(参加考试委员会)时,表现在20秒左右。

When I insert the CTE results into a temp table, and join onto that, the performance is instantaneous.

更不用说,似乎在条款的哪里上 h。 我认为,我的问题更何在于何时才开始计算并储存在记忆中? 我的假设是,它一劳永逸,然后在记忆中 stick,但在某些情况下,它可能被称为“ mu”。

问题回答

差异不是持续不变的,临时表格是(至少是届会)。 与已经预先评价的临时表格中的同一栏相比,没有数据中的数据。 基本上来说,你将使用的“快餐”和“服务器”能够更好优化。 在结合功能或表格变量的结果时,也会出现同样的问题。

My guess is that your CTE execution plan is doing the execution with a single thread while your temp table can use multiple threads. You can check this by including actual execution plan when you run the queries and looking for two horizontal arrows pointing in opposite directions on each operator. That indicates parallelism.

P.S. - Try establishing “set statistics io on” and “set statistics time on” to see if the actual cost ofîs the questions are same regardless ofîm.





相关问题
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: ...

热门标签