Home >Database >Mysql Tutorial >Reasons why a SQL statement becomes extremely slow and how to solve it

Reasons why a SQL statement becomes extremely slow and how to solve it

黄舟
黄舟Original
2017-02-20 11:38:131667browse

[Introduction] Phenomenon: A SQL suddenly runs very slowly. select uidTable column_value, first_name|| ||last_name, company, job_title, upper(member_level), upper(service_value)from (select * from table(select c

Phenomena: A SQL suddenly runs very slowly.




##Cause of error: The user added a condition member.site=test , causing the connection order to change. The original driver table is uidTable (up to 1024 records), and now it is driven by the member table (600W records), so this statement becomes extremely slow.

##But since it is an outer connection, why does the order of connections change? Because the connection order of outer connections is not determined by COST, but by the conditions of the connection. The execution plan is found as follows:





#Why not at all What about executing external joins? The problem lies in the condition member.site='test'. Because the condition is added to the external join table, the external join fails. After changing to member.site(+)='test', the problem is completely solved. .

The above is the reason why a SQL statement becomes extremely slow and its solution. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
#

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn