Help Center > > Developer Guide> Query Performance Optimization> Optimization Cases> Case: Rewriting SQL and Deleting Subqueries (Case 1)

Case: Rewriting SQL and Deleting Subqueries (Case 1)

Updated at: Jul 15, 2020 GMT+08:00

Symptom

1
2
3
4
select 
    1,
    (select count(*) from customer_address_001 a4 where a4.ca_address_sk = a.ca_address_sk) as GZCS 
from customer_address_001 a;

This SQL performance is poor. SubPlan exists in the execution plan as follows:

Optimization

The core of this optimization is to eliminate subqueries. Based on the service scenario analysis, a.ca_address_sk is not null. In terms of SQL syntax, you can rewrite the SQL statement as follows:

1
2
3
4
5
select 
count(*) 
from customer_address_001 a4, customer_address_001 a
where a4.ca_address_sk = a.ca_address_sk
group by  a.ca_address_sk;

To ensure that the modified statements have the same functions, not null is added to customer_address_001. ca_address_sk.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel