首先编辑q.sql如下
set explain on; set explain off; set explain on avoid_execute; set explain file to "/tmp/temp.out"; select count(*) from systables; select first 1 date(current) from systables #此处换成任意需要调整的sql
登陆informix服务器,执行dbaccess dbname a.sql结果如下
Database selected. Explain set. Explain set. Explain set. Explain set. (count(*)) 1142 1 row(s) retrieved. (expression) 11/20/2012 1 row(s) retrieved. Database closed.
查看详细任务计划 more /tmp/temp.out如下
UERY: (OPTIMIZATION TIMESTAMP: 11-20-2012 15:04:13) ------ select count(*) from tfa_alarm_relation Estimated Cost: 1 Estimated # of Rows Returned: 1 1) informix.tfa_alarm_relation: INDEX PATH (1) Index Name: (count) Index Keys: (count) Query statistics: ----------------- Table map : ---------------------------- Internal name Table name ---------------------------- type rows_prod est_rows rows_cons time ------------------------------------------------- group 1 1 0 00:00.00 QUERY: (OPTIMIZATION TIMESTAMP: 11-20-2012 15:04:13) ------ select first 1 date(current) from systables Estimated Cost: 78 Estimated # of Rows Returned: 1142 1) informix.systables: SEQUENTIAL SCAN Query statistics: ----------------- Table map : ---------------------------- Internal name Table name ---------------------------- t1 systables type table rows_prod est_rows rows_scan time est_cost ------------------------------------------------------------------- scan t1 1 1142 3 00:00.00 78 QUERY: (OPTIMIZATION TIMESTAMP: 11-20-2012 15:06:55) ------ select count(*) from systables Estimated Cost: 1 Estimated # of Rows Returned: 1 1) informix.systables: INDEX PATH
根据任务计划可以看出sql在哪一个环境耗时过长,进而对其进行优化。
下一节找一个这样的sql进行针对性练习