在含有子查询的SQL语句中,减少对表的查询是关键。例子:

低效:

SELECT TAB_NAME FROM TABLES WHERE TAB_NAME = (SELECT TAB_NAME FROM TAB_COLUMNS WHERE VERSION = 604) AND DB_VER = (SELECT DB_VER FROM TAB_COLUMNS WHERE VERSION = 604);

高效:

SELECT TAB_NAME FROM TABLES WHERE (TAB_NAME, DB_VER) IN (SELECT TAB_NAME, DB_VER FROM TAB_COLUMNS WHERE VERSION = 604);