Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SQL> CREATE TABLE foo (c1 NUMBER, c2 VARCHAR2(10));
- TABLE created.
- SQL> INSERT INTO foo SELECT 3, '003' FROM dual CONNECT BY LEVEL <= 1000000;
- 1000000 ROWS created.
- SQL> INSERT INTO foo SELECT 10, '010' FROM dual CONNECT BY LEVEL <= 1000000;
- 1000000 ROWS created.
- SQL> COMMIT;
- COMMIT complete.
- SQL> EXEC dbms_stats.gather_table_stats(USER,'foo');
- PL/SQL PROCEDURE successfully completed.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2=003;
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 952 (4)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1000K| 3906K| 952 (4)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter(TO_NUMBER("C2")=003)
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2=010;
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 952 (4)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 571K| 2232K| 952 (4)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter(TO_NUMBER("C2")=010)
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2='003';
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 942 (3)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1000K| 3906K| 942 (3)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter("C2"='003')
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2='010';
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 942 (3)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1000K| 3906K| 942 (3)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter("C2"='010')
- 14 ROWS selected.
- SQL> -- regather to make histogram
- SQL> EXEC dbms_stats.gather_table_stats(USER,'foo');
- PL/SQL PROCEDURE successfully completed.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2=003;
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 952 (4)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1 | 4 | 952 (4)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter(TO_NUMBER("C2")=003)
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2=010;
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 952 (4)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1 | 4 | 952 (4)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter(TO_NUMBER("C2")=010)
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2='003';
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 942 (3)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 1000K| 3906K| 942 (3)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter("C2"='003')
- 14 ROWS selected.
- SQL> EXPLAIN PLAN FOR
- 2 SELECT COUNT(*) FROM foo WHERE c2='010';
- Explained.
- SQL> SELECT * FROM TABLE(dbms_xplan.display());
- PLAN_TABLE_OUTPUT
- -------------------------------------------------------------------------------
- PLAN hash VALUE: 1342139204
- ---------------------------------------------------------------------------
- | Id | Operation | Name | ROWS | Bytes | COST (%CPU)| TIME |
- ---------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 4 | 942 (3)| 00:00:12 |
- | 1 | SORT AGGREGATE | | 1 | 4 | | |
- |* 2 | TABLE ACCESS FULL| FOO | 999K| 3904K| 942 (3)| 00:00:12 |
- ---------------------------------------------------------------------------
- Predicate Information (IDENTIFIED BY operation id):
- ---------------------------------------------------
- 2 - filter("C2"='010')
- 14 ROWS selected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement