![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi All, I have one question about many "or" operation make system choose incorrect index There is one table TT ( C1 VARCHAR(15) NOT NULL, C2 VARCHAR(15) NOT NULL, C3 VARCHAR(15) NOT NULL, C4 VARCHAR(15) NOT NULL C5 VARCHAR2(200), ) Primary Key TT_PK (C1, C2, C3, C4) SELECT C1, C2, C3, C4 FROM TT WHERE C1 = 'TEST' AND ((C2 = '07RES' AND C3 = '00000' AND C4 = '02383') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02382') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02381') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02380') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02379') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02378') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02377') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02376') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02375') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02374') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02373') OR (C2 = '07RES' AND C3 = '00000' AND C4 = '02372') ... about 100 or operations OR (C2 = '07COM' AND C3 = '00000' AND C4 = '00618') OR (C2 = '07COM' AND C3 = '00000' AND C4 = '00617') OR (C2 = '07COM' AND C3 = '00000' AND C4 = '00616') OR (C2 = '07COM' AND C3 = '00000' AND C4 = '00608') ) The system choose index prefix, and query all index leaf with C1='TEST' Prefix: [dbo].[TT].C1 = 'TEST' After I reduce the OR operators to 50, it use choose Prefix: [dbo].[TT].C1, [dbo].[TT].C2,[dbo].[TT].C3,[dbo].[TT].C4= 'TEST, '07RES', '00000', '02383' Then Merge Join, it is very quick, Can anyone help on this, do I have to reduce the OR operator to 50? Thanks in advance! |
#3
| |||
| |||
|
|
Please note that there is a certain point at which the compilation time grows a lot for each addition predicate you add to the WHERE clause. If the compilation time exceeds the estimated gains, the optimizer will stop compilation and simply choose a "good enough" plan. |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Hi Gert-Jan/Erland Sommarskog, Thanks for your input. The whole sql is very long. ... yes, I have reduced the OR number to 62, the optimizer chooses different index plan. When there are 63 OR operators, the optimizer chooses the partial index scan Seek predicts : Prefix: [sacco].[dbo].[BCHCKBOX].SERV_PROV_CODE = 'SACCO' |
|
Where can I found the document of 63 is the value? |
|
Because multiple client access the site, I don't know how to use temporary table to do it, could you give me one example? |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
lsllcm (lsl... (AT) gmail (DOT) com) writes: Hi Gert-Jan/Erland Sommarskog, Thanks for your input. The whole sql is very long. ... yes, I have reduced the OR number to 62, the optimizer chooses different index plan. When there are 63 OR operators, the optimizer chooses the partial index scan Seek predicts : Prefix: [sacco].[dbo].[BCHCKBOX].SERV_PROV_CODE = 'SACCO' Seeing you SQL, performance appears to be your smallest problem. That code must be about unmaintainable. I would get those values in to a table. That may or may not help you to the best performance, but at least you will be better equipped to battle the problems. Where can I found the document of 63 is the value? I doubt that it's documented. I found it on my own by testing. Because multiple client access the site, I don't know how to use temporary table to do it, could you give me one example? I don't see why the multiple clients would cause the problem. But since I don't where you get all these values from or much at all about your system, I cannot any examples. Did you say which version of SQL Server you are using`? -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
#9
| |||
| |||
|
|
Could you provide the test step of 63 value |
![]() |
| Thread Tools | |
| Display Modes | |
| |