English 中文(简体)
SQL SQL 工会间接费用
原标题:SQL Union overhead

Im having a performance issue on using union. I have two sql queries with same column results but from different tables:

SELECT COL1, COL2, COL3
FROM TABLE1

(需要大约4秒完成)和:

SELECT COL1, COL2, COL3
FROM TABLE2 INNER JOIN TABLE3 ON ID

这需要大约4秒完成。当我使用 < code> UNionion ALL 来完成这两个查询时,结果需要22秒才能完成。

是否有改进业绩的建议?

问题回答

UNION 条款通过在选择条款上使用 DISTINCT 并创建一些临时表格来消除重复内容,这些表格是符合要求的昂贵任务。 您是否需要这些重复内容?

校对""http://blog.sql authority.com/2009/03/11/sql-server-difference- between-union-vs-union-s-union-all-optimal-proper-compararison/" rel=“nofollow”> Pinnal Dave 对使用UNION和UNION All进行详细分析,并分析执行计划。

我还想检查这些选择条款是否正确使用指数,但很难说没有详细查看表格结构。

尝试使用 UNion all - 它避免找到重复。 没有 UNion DistinT , 不使用 UNion DistinT , 是一种良好做法, 但您需要的除外 。

与业绩问题一样:衡量。

下一步是从数据库中获取执行计划,然后看看。如果你不理解计划,打开一个新问题。





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

热门标签