![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Table T ( MACHINE_ID varchar(24) not null, COLLECT_TIME TIMESTAMP not null, DISK_ID *varchar(60) not null, BYTES bigint not null, DISKIO integer not null ); alter table T add constraint PK primary key (MACHINE_ID, COLLECT_TIME, DISK_ID). There is not other defined index. This table has updated statistics and contains 800M+ rows. The following query runs for 11 minutes: select MACHINE_ID, COLLECT_TIME, DISK_ID, BYTES, TMACT,TPS from bi.t_minute_diskio where machine_id = '002481D161ABB73C41BA6302' * * * * * and collect_time between '2011-04-01 00:00:00.0' and '2011-04-30 23:59:59.0' * * * * * and disk_id = 'hdisk1' * * * and TMACT between 0 and 60 The plan shows an IXSCAN on the existing index created for the PK. db2advis recommends: * *CREATE INDEX DB2INST1.IDX1105041205410 ON T * * * * * (DISK_ID ASC, TMACT DESC) * *ALLOW REVERSE SCANS * *COLLECT SAMPLED DETAILED STATISTICS; This index would reduce the query cost in 98%. *Index size is 6GB in space, so I can't easily create it. The query uses MACHINE_ID, COLLECT_TIME, DISK_ID and TMACT as predicates. The suggested index contains (DISK_ID, TMACT). Will DB2 try to combine both indexes here? MACHINE_ID is our main identifier in the system and the suggested index will not even use it. Is there any way to simulate the final access plan without creating the index? Thanks, -M |
#3
| |||
| |||
|
|
Table T ( MACHINE_ID varchar(24) not null, COLLECT_TIME TIMESTAMP not null, DISK_ID varchar(60) not null, BYTES bigint not null, DISKIO integer not null ); alter table T add constraint PK primary key (MACHINE_ID, COLLECT_TIME, DISK_ID). There is not other defined index. This table has updated statistics and contains 800M+ rows. The following query runs for 11 minutes: select MACHINE_ID, COLLECT_TIME, DISK_ID, BYTES, TMACT,TPS from bi.t_minute_diskio where machine_id = '002481D161ABB73C41BA6302' and collect_time between '2011-04-01 00:00:00.0' and '2011-04-30 23:59:59.0' and disk_id = 'hdisk1' and TMACT between 0 and 60 The plan shows an IXSCAN on the existing index created for the PK. db2advis recommends: CREATE INDEX DB2INST1.IDX1105041205410 ON T (DISK_ID ASC, TMACT DESC) ALLOW REVERSE SCANS COLLECT SAMPLED DETAILED STATISTICS; This index would reduce the query cost in 98%. Index size is 6GB in space, so I can't easily create it. The query uses MACHINE_ID, COLLECT_TIME, DISK_ID and TMACT as predicates. The suggested index contains (DISK_ID, TMACT). Will DB2 try to combine both indexes here? MACHINE_ID is our main identifier in the system and the suggested index will not even use it. |
|
Is there any way to simulate the final access plan without creating the index? |
#4
| |||
| |||
|
|
Table T ( MACHINE_ID varchar(24) not null, COLLECT_TIME TIMESTAMP not null, DISK_ID *varchar(60) not null, BYTES bigint not null, DISKIO integer not null ); alter table T add constraint PK primary key (MACHINE_ID, COLLECT_TIME, DISK_ID). There is not other defined index. This table has updated statistics and contains 800M+ rows. The following query runs for 11 minutes: select MACHINE_ID, COLLECT_TIME, DISK_ID, BYTES, TMACT,TPS from bi.t_minute_diskio where machine_id = '002481D161ABB73C41BA6302' * * * * * and collect_time between '2011-04-01 00:00:00.0' and '2011-04-30 23:59:59.0' * * * * * and disk_id = 'hdisk1' * * * and TMACT between 0 and 60 The plan shows an IXSCAN on the existing index created for the PK. db2advis recommends: * *CREATE INDEX DB2INST1.IDX1105041205410 ON T * * * * * (DISK_ID ASC, TMACT DESC) * *ALLOW REVERSE SCANS * *COLLECT SAMPLED DETAILED STATISTICS; This index would reduce the query cost in 98%. *Index size is 6GB in space, so I can't easily create it. The query uses MACHINE_ID, COLLECT_TIME, DISK_ID and TMACT as predicates. The suggested index contains (DISK_ID, TMACT). Will DB2 try to combine both indexes here? MACHINE_ID is our main identifier in the system and the suggested index will not even use it. Is there any way to simulate the final access plan without creating the index? Thanks, -M Is there any way to simulate the final access plan without creating the index? Try SET CURRENT EXPLAIN MODE EVALUATE INDEXES |
#5
| |||
| |||
|
|
Just some thinking, what is firstkeycard for the existing index? I.e. how many distinct machine_id is there? If the number is low the selectivity for machine_id = '002481D161ABB73C41BA6302' will be poor. What is: * * select count(distinct DISK_ID) from bi.t_minute_diskio? |
|
Are you using parameter markers for collect_time in your query, or are they hard-coded as shown in your query? The between predicate is tricky when it comes to parameter markers, adding a selectivity clause for that predicate in the query might help. |
#6
| ||||||||
| ||||||||
|
|
Are you using parameter markers for collect_time in your query, or are they hard-coded as shown in your query? The between predicate is tricky when it comes to parameter markers, adding a selectivity clause for that predicate in the query might help. Yes, we are using parameter markers. I am not sure what you mean by adding a selectivity clause. Show I not use parameter markers in this case? |
| 58.444 |
|
/---+----\ 1 584.44 14611 |
| 14611 |
| 23.3776 |
| 23.3776 |
| 23.3776 |
|
| 14611 14611 |
#7
| |||
| |||
|
|
Lennart, Just some thinking, what is firstkeycard for the existing index? I.e. how many distinct machine_id is there? If the number is low the selectivity for machine_id = '002481D161ABB73C41BA6302' will be poor. What is: * * select count(distinct DISK_ID) from bi.t_minute_diskio? FirstKeyCard for the existing index is around 1800. The count of distinct DISK_IDs is aroung 6000. Now I understand why Db2 suggests DISK_ID as a first column. Are you using parameter markers for collect_time in your query, or are they hard-coded as shown in your query? The between predicate is tricky when it comes to parameter markers, adding a selectivity clause for that predicate in the query might help. Yes, we are using parameter markers. I am not sure what you mean by adding a selectivity clause. Show I not use parameter markers in this case? joklassen, I did not know about that option in set current explain. That was exactly what I needed. Thanks guys, -M I will create the suggested index in production and let you know the results. |
#8
| |||
| |||
|
|
Lennart, Just some thinking, what is firstkeycard for the existing index? I.e. how many distinct machine_id is there? If the number is low the selectivity for machine_id = '002481D161ABB73C41BA6302' will be poor. What is: * * select count(distinct DISK_ID) from bi.t_minute_diskio? FirstKeyCard for the existing index is around 1800. The count of distinct DISK_IDs is aroung 6000. Now I understand why Db2 suggests DISK_ID as a first column. Are you using parameter markers for collect_time in your query, or are they hard-coded as shown in your query? The between predicate is tricky when it comes to parameter markers, adding a selectivity clause for that predicate in the query might help. Yes, we are using parameter markers. I am not sure what you mean by adding a selectivity clause. Show I not use parameter markers in this case? joklassen, I did not know about that option in set current explain. That was exactly what I needed. Thanks guys, -M I will create the suggested index in production and let you know the results. |
![]() |
| Thread Tools | |
| Display Modes | |
| |