The previous article introduced how to explain the struct and array in Oracle,
- Explain plan
- Select * from table (dept_array (department_type (
- 1, -- DNO number (10 ),
- 'Name', -- name varchar2 (50 ),
- 'Location' -- location varchar2 (50)
- ) T
- Join Table2 T2 on T. DNO = t2.dno;
- Select * from table (dbms_xplan.display );
The running result contains the following data:
- Plan_table_output
- 1 plan hash value: 1748000095
- 2
- 3 Cores ----------------------------------------------------------------------------------------------
- 4 | ID | operation | Name | rows | bytes | cost (% CPU) | time |
- 5 Cores ----------------------------------------------------------------------------------------------
- 6 | 0 | SELECT statement |8168| 16336 | 24 (0) | 00:00:01 |
- 7 | 1 | collection iterator constructor fetch |
- 8 bytes ----------------------------------------------------------------------------------------------
By default, the number of data rows in array is 8168. However, the number of rows in array varies depending on different scenarios. Use cardinality hint to let optimizer know the number of rows in the array.
- Explain plan
- Select/* + cardinality (T10) */* From table (dept_array (department_type (
- 1, -- DNO number (10 ),
- 'Name', -- name varchar2 (50 ),
- 'Location' -- location varchar2 (50)
- ) T
- Join Table2 T2 on T. DNO = t2.dno;
- Select * from table (dbms_xplan.display );
Running result:
- Plan_table_output
- 1 plan hash value: 1748000095
- 2
- 3 Cores ----------------------------------------------------------------------------------------------
- 4 | ID | operation | Name | rows | bytes | cost (% CPU) | time |
- 5 Cores ----------------------------------------------------------------------------------------------
- 6 | 0 | SELECT statement |10| 20 | 24 (0) | 00:00:01 |
- 7 | 1 | collection iterator constructor fetch |
- 8 bytes ----------------------------------------------------------------------------------------------
The number 10 is the maximum number of rows in array.
Refer:
The cardinality hint when you are using PL/SQL collections in SQL