के लिए जांच करते समय सर्वश्रेष्ठ स्व-तकनीक तकनीक में शामिल हों, मैं उत्पादन में मौजूद एक क्वेरी को अनुकूलित करने की कोशिश कर रहा हूं जो लंबे समय से ले रहा है। लक्ष्य मिलान मूल्य मान मानदंडों के आधार पर डुप्लिकेट रिकॉर्ड ढूंढना और फिर उन्हें हटाना है। वर्तमान क्वेरी t1.col1 = t2.col1 पर आंतरिक जुड़ने के माध्यम से स्वयं को शामिल करने का उपयोग करती है, फिर मानों की जांच करने के लिए एक खंड।डुप्लीकेट
select * from table t1
inner join table t2 on t1.col1 = t2.col1
where t1.col2 = t2.col2 ...
ऐसा करने का बेहतर तरीका क्या होगा? या यह इंडेक्स पर आधारित सभी समान है? शायद
select * from table t1, table t2
where t1.col1 = t2.col1, t2.col2 = t2.col2 ...
इस तालिका में 100 मीटर + पंक्तियां हैं।
एमएस एसक्यूएल, एसक्यूएल सर्वर 2008 एंटरप्राइज़
select distinct t2.id
from table1 t1 with (nolock)
inner join table1 t2 with (nolock) on t1.ckid=t2.ckid
left join table2 t3 on t1.cid = t3.cid and t1.typeid = t3.typeid
where
t2.id > @Max_id and
t2.timestamp > t1.timestamp and
t2.rid = 2 and
isnull(t1.col1,'') = isnull(t2.col1,'') and
isnull(t1.cid,-1) = isnull(t2.cid,-1) and
isnull(t1.rid,-1) = isnull(t2.rid,-1)and
isnull(t1.typeid,-1) = isnull(t2.typeid,-1) and
isnull(t1.cktypeid,-1) = isnull(t2.cktypeid,-1) and
isnull(t1.oid,'') = isnull(t2.oid,'') and
isnull(t1.stypeid,-1) = isnull(t2.stypeid,-1)
and (
(
t3.uniqueoid = 1
)
or
(
t3.uniqueoid is null and
isnull(t1.col1,'') = isnull(t2.col1,'') and
isnull(t1.col2,'') = isnull(t2.col2,'') and
isnull(t1.rdid,-1) = isnull(t2.rdid,-1) and
isnull(t1.stid,-1) = isnull(t2.stid,-1) and
isnull(t1.huaid,-1) = isnull(t2.huaid,-1) and
isnull(t1.lpid,-1) = isnull(t2.lpid,-1) and
isnull(t1.col3,-1) = isnull(t2.col3,-1)
)
)
एमएस एसक्यूएल? यदि हां, तो SQL सर्वर का कौन सा संस्करण? –
@ ब्रूनो क्षमा करें, मैंने प्रश्न और टैग अपडेट किया है –
@ मिच नहीं, यह एक ही तालिका में शामिल होने वाली एक तालिका है। यह कैसे शामिल नहीं है? –