admin管理员组文章数量:1122846
I'm trying to optimize the performance of a SQL query by creating an index on one or more columns, but it seems that the index is not being used as expected. The query is still performing a full table scan. I am using Oracle database.
I’m looking to reduce the cost of the query. In the explain plan, many of the joins are using full table scans, which is significantly impacting performance. Our most recent attempt resulted in the query running for an hour on the server.
My select is build like this:
INSERT INTO VM_PEDIDO
SELECT *
FROM V_PEDIDO_V1
WHERE CD_TIPONOTA NOT IN ('190','308','6090');
The explain plan is this:
| Id | Operation | Name | Rows | Bytes | Cost | Time |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 22760 | 24M | 231K | 00:00:10|
| 1 | HASH JOIN RIGHT OUTER | | 22760 | 24M | 231K | 00:00:10|
| 2 | VIEW | V_ITEM_MASCARA | 5534 | 1432K | 41 | 00:00:01|
| 4 | TABLE ACCESS BY INDEX ROWID BATCHED | ETL_V_ITEM_MASCARA_CONS | 3697 | 108K | 27 | 00:00:01|
| 5 | INDEX RANGE SCAN | ETL_V_ITEM_MASCARA_CONS_INDEX1 | 3697 | | 7 | 00:00:01|
| 6 | TABLE ACCESS BY INDEX ROWID BATCHED | ETL_V_ITEM_MASCARA_BASE | 1837 | 58784 | 14 | 00:00:01|
| 7 | INDEX RANGE SCAN | ETL_V_ITEM_MASCARA_BASE_INDEX2 | 1837 | | 4 | 00:00:01|
| 8 | HASH JOIN RIGHT OUTER | | 9990 | 8253K | 231K | 00:00:10|
| 9 | TABLE ACCESS FULL | TAUX_TAB_ICMS | 11760 | 149K | 17 | 00:00:01|
| 10 | HASH JOIN RIGHT OUTER | | 9990 | 8126K | 231K | 00:00:10|
| 11 | TABLE ACCESS FULL | ETL_V_ITEM_PESO_CONS | 3728 | 22368 | 5 | 00:00:01|
| 12 | HASH JOIN RIGHT OUTER | | 9990 | 8068K | 231K | 00:00:10|
| 13 | TABLE ACCESS FULL | TAUX_PRODUTO | 347 | 3123 | 3 | 00:00:01|
| 14 | HASH JOIN RIGHT OUTER | | 9990 | 7980K | 231K | 00:00:10|
| 15 | TABLE ACCESS FULL | TAUX_PRODSEMFARDO | 29 | 203 | 3 | 00:00:01|
| 16 | HASH JOIN | | 9990 | 7912K | 231K | 00:00:10|
| 17 | TABLE ACCESS FULL | TAUX_PRODUTOS | 13294 | 363K | 25 | 00:00:01|
| 18 | HASH JOIN | | 9990 | 7638K | 231K | 00:00:10|
| 19 | HASH JOIN RIGHT OUTER | | 66 | 34386 | 227K | 00:00:09|
| 20 | TABLE ACCESS FULL | TAUX_FORMA_PGTO | 825 | 9075 | 4 | 00:00:01|
| 21 | HASH JOIN OUTER | | 66 | 33660 | 227K | 00:00:09|
| 22 | HASH JOIN OUTER | | 6 | 3024 | 227K | 00:00:09|
| 23 | HASH JOIN OUTER | | 6 | 2844 | 227K | 00:00:09|
| 24 | HASH JOIN OUTER | | 6 | 2772 | 227K | 00:00:09|
| 25 | HASH JOIN OUTER | | 5 | 2250 | 227K | 00:00:09|
| 26 | JOIN FILTER CREATE | :BF0000 | 5 | 795 | 227K | 00:00:09|
| 27 | MERGE JOIN OUTER | | 5 | 795 | 227K | 00:00:09|
| 28 | SORT JOIN | | 5 | 735 | 227K | 00:00:09|
| 29 | VIEW | V_PEDIDO | 5 | 735 | 227K | 00:00:09|
| 30 | UNION-ALL | | | | | |
| 31 | TABLE ACCESS FULL | ETL_V_PEDIDO_CONS | 4 | 324 | 216K | 00:00:09|
| 32 | TABLE ACCESS FULL | ETL_V_PEDIDO_BASE | 1 | 77 | 11034 | 00:00:01|
| 33 | FILTER | | | | | |
| 34 | SORT JOIN | | 1 | 12 | 4 | 00:00:01|
| 35 | TABLE ACCESS FULL | VM_CAD_PEDI_JUROS | 1 | 12 | 3 | 00:00:01|
| 36 | VIEW | | 46 | 13386 | 7 | 00:00:01|
| 37 | HASH GROUP BY | | 46 | 736 | 7 | 00:00:01|
| 38 | VIEW | V_BLOQ_CREDITO | 46 | 736 | 6 | 00:00:01|
| 39 | JOIN FILTER USE | :BF0000 | | | | |
| 40 | UNION-ALL | | | | | |
| 41 | TABLE ACCESS FULL | ETL_V_BLOQ_CREDITO_CONS | 42 | 630 | 3 | 00:00:01|
| 42 | TABLE ACCESS FULL | ETL_V_BLOQ_CREDITO_BASE | 4 | 60 | 3 | 00:00:01|
| 43 | TABLE ACCESS FULL | TAUX_DESCONTO_CLIENTE | 624 | 7488 | 3 | 00:00:01|
| 44 | TABLE ACCESS FULL | TAUX_GRUPOCLI | 2602 | 31224 | 5 | 00:00:01|
| 45 | TABLE ACCESS FULL | TAUX_CLIENTES2 | 33325 | 976K | 77 | 00:00:01|
| 46 | TABLE ACCESS FULL | TAUX_TIPOFRETE | 52 | 312 | 3 | 00:00:01|
| 47 | VIEW | V_ITEM_PEDIDO_V2 | 1524K | 380M | 4629 | 00:00:01|
| 48 | UNION-ALL | | | | | |
| 49 | TABLE ACCESS FULL | ETL_V_ITEM_PEDIDO_V2_CONS | 14 | 149 | 5 | 00:00:01|
| 50 | TABLE ACCESS FULL | ETL_V_ITEM_PEDIDO_V2_BASE | 655 | 6332 | 16 | 00:00:01|
I guess the main cost is being produced in line 31.
I tried to create a indexes like this:
CREATE INDEX idx_cd_tiponota_check ON V_PEDIDO_V1 (
CASE
WHEN CD_TIPONOTA IN ('190', '308', '6090') THEN NULL
ELSE CD_TIPONOTA
END
);
and this:
CREATE INDEX idx_cd_tiponota_check ON ETL_V_PEDIDO_BASE(CODTIPONOTA)
this is where i guess is the highest cost:
本文标签: oracle databaseTrying to improve my SQL performance costindex is not being usedStack Overflow
版权声明:本文标题:oracle database - Trying to improve my SQL performance cost, index is not being used - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307707a1933407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论