Recently, when using select query in a project, I used not in to exclude the unused primary key ID. The SQL used at the beginning was as follows: select s.SORT_ID, s.SORT_NAME, s.SORT_STATUS, s.SORT_LOGO_URL, s.SORT_LOGO_URL_LIGHT from SYS_SORT_PROMOTE s WHERE s.SORT_NAME = 'Must-Listen Classics' AND s.SORT_ID NOT IN ("SORTID001") limit 1; When there is a lot of data in the table, the execution time of this SQL is long and the execution efficiency is low. I found information online that it can be optimized using left join. The optimized SQL is as follows: select s.SORT_ID, s.SORT_NAME, s.SORT_STATUS, s.SORT_LOGO_URL, s.SORT_LOGO_URL_LIGHT from SYS_SORT_PROMOTE s left join (select SORT_ID from SYS_SORT_PROMOTE where SORT_ID=#{sortId}) b on s.SORT_ID = b.SORT_ID WHERE b.SORT_ID IS NULL AND s.SORT_NAME = 'Must-Listen Classics' limit 1; In the above SORT_ID=#{sortId}, sortId passes in the ID value that needs to be excluded in the SORT_ID field. When performing a left outer join, the field to be filtered (SORT_ID) is used as the join condition. Finally, add b.SORT_ID IS NULL to the where condition to filter out the related data in the table. Write down the essay here to record the optimization process. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: A practical record of troubleshooting a surge in Redis connections in Docker
>>: Detailed tutorial on installing Python 3 virtual environment in Ubuntu 20.04
Table of contents Observer Pattern Vue pass value...
Table of contents Overview Install Gulp.js Create...
Table of contents background 1. Document Descript...
Problem description (what is keep-alive) keep-ali...
This article uses examples to describe various co...
In many cases, in order to beautify the form, the ...
Before talking about the structural markup of web...
1. Requirements When using the Vue.js framework t...
Look at the code: Copy code The code is as follows...
Table of contents 1. Download the virtual machine...
Table of contents Preface Rolling principle accom...
A simple example of how to use the three methods ...
The following is the code for building an ssh ser...
Table of contents Use of CURRENT_TIMESTAMP timest...
Unzip the Maven package tar xf apache-maven-3.5.4...