-1
我有一個包含300列和超過1.2億條記錄的表。我想執行一個查詢,如SQL查詢 - 包含300列和1.2億條記錄的表
select *
from tablename
where code in ('aa','bb', ..)
and column1 in ('a11','a22',..)
有大約50多列需要應用條件。
執行此查詢需要兩個多小時。有沒有辦法改善這一點?
Select查詢語句是:
SELECT Number, COUNT(Code) AS Volume
FROM TableNameTest
WHERE LEN(Number) >= 5
AND Code IN ('851','852','853','870','871','872','002','004','006','013','017')
AND (ColumnName IN ('N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName2 IN ('N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName3 IN ('N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName4 IN ('N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName5 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName6 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName7 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName8 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName9 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName10 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName11 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName12 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName13 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName14 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName15 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName16 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName17 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName18 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName19 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName20 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName21 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName22 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName23 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName24 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName25 IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
) AND (ColumnName NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName2 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName3 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName4 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName5 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName6 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName7 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName8 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName9 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName10 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName11 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName12 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName13 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName14 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName15 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName16 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName17 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName18 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName19 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName20 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName21 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName22 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName23 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName24 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
OR ColumnName25 NOT IN (
'N179','R9002','R40.2240','R40.2241','R40.2242','R40.2243','R40.2244','R40.2245','R40.2246','R40.2247','R40.2248','R40.2249','R40.2230','R40.2231','R40.2232','R40.2233','R40.2234','R40.2235','R40.2236','R40.2237','R40.2238','R40.2239','N289','R410','R34','N178','J80')
)) group by Number Order by Number
`
請發佈架構和查詢的解釋。 –
已添加有問題的執行計劃 –
執行計劃中的查詢看起來並不相同 - 它顯然使用了聚合函數。另外,如果沒有模式,我們只是猜測 - 表中是否有索引? –