Use the trim () method cautiously in the where statement when SQL Server Multiple table Association _mssql
Source: Internet
Author: User
Similar to the following:
Select A.key,b.key,c.key from A,b,c where trim (a.key) =trim (B.FK) and trim (A.col) =trim (c.pk).
In Table A (more than 200 records), the associated schedule B (more than 40,000 records) was used for 1 seconds, which may vary between machines, but slightly slower than the trim speed, but not particularly noticeable.
Its SQL statement resembles the following:
Select A.key,b.key from A,b where trim (a.key) =trim (B.FK)
However, after adding the third table C (two records) to the above SQL statement, the SQL statement is as follows:
Select A.key,b.key,c.key from A,b,c where trim (a.key) =trim (B.FK) and trim (A.col) =trim (c.pk)
The entire SQL statement was executed for almost more than 70 seconds. It costs 60 more seconds than no trim () method.
Later, several experiments were carried out to find out the multiple-table association condition in the where, if it was not added to the left-side associated condition, it could achieve the basic equivalent to the General Multiple Table Association.
The improved SQL statement is as follows:
Select A.key,b.key,c.key from A,b,c where A.key=trim (B.FK) and A.col=trim (c.pk)
The execution efficiency of this SQL statement is essentially equivalent to the speed of the SQL statement without the trim () in the WHERE statement.
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.