(index name) whereNum = @ num 7. Avoid performing expression operations on fields in the where clause as much as possible, which will cause the engine to discard the use of indexes for full table scanning. For example:SELECT * FROM T1 WHERE F1/2 = 100Should be changed:SELECT * FROM T1 WHERE F1 = 100*2SELECT * from record where substring (CARD_NO, 5378) = '20140901'Should be changed:SELECT * from record where CARD_NO LIKE '201312'SELECT member_number,
-- use set showplanon to open the showplan option and you will see the connectionThe order of access and the index information used. For more detailed information, you need to use the SA role to execute DBCC (3604,310, 302 ).3. Where clause that cannot be optimized---- 1. For example, the columns in the following SQL condition statements have an appropriate index, but the execution speed is very slow:Select * from record whereSubstring (card_no, 5378
varbinary are incompatible. Data Type incompatibility may make the optimizer unable to perform some optimization operations that can be performed originally. For example:Select name from employee where salary> 60000In this statement, if the salary field is of the money type, it is difficult for the optimizer to optimize it because 60000 is an integer. We should convert the integer type into a coin type during programming, instead of waiting for the conversion at runtime.
3. Avoid performing f
, char and varchar, binary, andVarbinary is incompatible. Incompatible data types may make the optimizer unable to execute some operations that can be imported. For example:Select name from employee where salary> 60000In this statement, if the salary field is of the money type, it is difficult for the optimizer to optimize it because 60000It is an integer. We should convert the integer type into a coin type during programming, instead of waiting for the conversion at runtime.
3. Avoid performi
varbinary are incompatible. Data Type incompatibility may make the optimizer unable to perform some optimization operations that can be performed originally. For example:Select name from employee where salary> 60000In this statement, if the salary field is of the money type, it is difficult for the optimizer to optimize it because 60000 is an integer. We should convert the integer type into a coin type during programming, instead of waiting for the conversion at runtime.
3. Avoid performing f
executed for the best solution.---- Conclusion:---- 1. Before a multi-table operation is executed, the query optimizer will list several groups of possible connected parties based on the connection conditions.And find the best solution with the minimum system overhead. The connection conditions must fully consider the tables with indexes and the number of rowsTable; the choice of the internal and external table can be determined by the formula: Number of matched rows in the outer table * Number
varbinary are incompatible. Data Type incompatibility may make the optimizer unable to perform some optimization operations that can be performed originally. For example:Select name from employee where salary> 60000In this statement, if the salary field is of the money type, it is difficult for the optimizer to optimize it because 60000 is an integer. We should convert the integer type into a coin type during programming, instead of waiting for the conversion at runtime. 3. Avoid performing fu
, the columns in the following SQL condition statements have an appropriate index, but the execution speed is very slow:
Select * from record where
Substring (card_no, 5378) = '000000' (13 seconds)
Select * from record where
Amount/30 Select * from record where
Convert (char (10), date, 112) = '000000' (10 seconds)
---- Analysis:
---- Any column operation results in the WHERE clause are calculated by column during SQL Execution, so it has
The index on
record where substring (card_no, 5378) = '20140901'(13 seconds)Select * from record where amount/30 (11 seconds)Select * from record where convert (char (10), date, 112) = '20140901'(10 seconds)Analysis:Any operation results on the column in The WHERE clause are calculated by column one by one during SQL Execution. Therefore, it has to perform table search without using the index on the column; if these results are obtained during query compilation,
inner table account) = 7896 times I/OIt can be seen that only a full set of connection conditions can be executed for the best solution.Before a multi-table operation is executed, the query optimizer lists several possible connection schemes based on the connection conditions and finds the optimal scheme with the minimum system overhead. The join conditions must fully consider the tables with indexes and tables with multiple rows. The selection of the internal and external tables can be determi
-- use set showplanon to open the showplan option and you will see the connectionThe order of access and the index used. For more detailed information, you need to use the SA role to execute DBCC (3604,310, 302 ).3. Where clause that cannot be optimized---- 1. For example, the columns in the following SQL condition statements have an appropriate index, but the execution speed is very slow:Select * from record whereSubstring (card_no, 5378) = '000000'
, the columns in the following SQL condition statements have an appropriate index, but the execution speed is very slow:
Select * from record where
Substring (card_no, 5378) = '000000' (13 seconds)
Select * from record where
Amount/30 Select * from record where
Convert (char (10), date, 112) = '000000' (10 seconds)
---- Analysis:
---- Any column operation results in the where clause are calculated by column during SQL Execution, so it has
The index on
StarsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 5378 Accepted Submission (s): 2125Problem descriptionastronomers often examine star maps where stars is represented by points on a plane and All star has Cartesian coordinates. The level of a star is a amount of the stars that is not higher and is not the right of the given star. Astronomers want to know the distribution of the levels of the star
* from T1 WHERE f1/2=100should read:SELECT * from T1 WHERE f1=100*2SELECT * from RECORD WHERE SUBSTRING (card_no,1,4) = ' 5378 'should read:SELECT * from RECORD WHERE card_no like ' 5,378% 'SELECT Member_number, first_name, last_name from membersWHERE DATEDIFF (Yy,datofbirth,getdate ()) > 21should read:SELECT Member_number, first_name, last_name from membersWHERE dateOfBirth That is, any action on a column causes a table scan, which includes database
instead of forcing the query:
Select ID from T with (index name) where num= @num
7. You should try to avoid the expression of fields in the WHERE clause, which will cause the engine to discard the use of indexes for full table scans. Such as:
SELECT * from T1 WHERE f1/2=100
should read:
SELECT * from T1 WHERE f1=100*2
SELECT * FROM record WHERE SUBSTRING (card_no,1,4) = ' 5378 '
should read:
SELECT * FROM record WHERE card_no like ' 5,378% '
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.