Use_concat prompts to force each or predicate in the optimizer to extend a query as a separate query block.
Finally, the results of all query blocks are merged, and the result set is returned to the user.
When using multiple in-lists queries, Oracle may choose to extend a single query to multiple query blocks.
Example of using the USE_CONCAT hint:
1. Use Scott's user and standard table for testing
$ sqlplus scott/tigersql*plus:release 9.2.0.4.0-production on Wed Nov 15:17:51 2004Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to:oracle9i Enterprise Edition release 9.2.0.4.0-64bit productionwith The partitioning, OLAP and Oracle Data M Ining optionsjserver Release 9.2.0.4.0-productionsql> set Autotrace onsql> select * from emp where empno in (7788), 7900); EMPNO ename JOB MGR hiredate SAL COMM DEPTNO----------------------------------------------------------------------- -------7788 SCOTT ANALYST 7566 19-apr-87 3000 7900 JAMES clerk 7698 03-dec-81 950 30Execution plan-------------------- --------------------------------------0 SELECT STATEMENT optimizer=choose (cost=2 card=2 bytes=74) 1 0 TABLE ACCESS (full of ' EMP ' (cost=2 card=2 bytes=74)-Note that Oracle has selected a full table scan here because of its lower cost. Statistics----------------------------------------------------------0 Recursive calls 0 DB block gets 4 consistent gets 0 Physical reads 0 Redo size 1032 Bytes Sent Via sql*net to client 655 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 s Orts (disk) 2 rows processed
2. Add Tips
Sql> Select/*+ use_concat * * from EMP where empno in (7788,7900); EMPNO ename JOB MGR hiredate SAL COMM DEPTNO----------------------------------------------------------------------- -------7900 JAMES Clerk 7698 03-dec-81 950 7788 SCOTT ANALYST 7566 19-apr-87 3000 20Execution plan-------------------- --------------------------------------0 SELECT STATEMENT optimizer=choose (cost=4 card=2 bytes=74) 1 0 concatenation 2 1 TABLE ACCESS (by INDEX ROWID) of ' EMP ' (cost=2 card=1 bytes=37) 3 2 INDEX (unique SCAN) of ' pk_emp ' (unique) (Cost=1 card= 4 1 TABLE ACCESS (by INDEX ROWID) of the ' EMP ' (cost=2 card=1 bytes=37) 5 4 INDEX (unique SCAN) of ' pk_emp ' (unique) (cost =1 card=14)--After using the USE_CONCAT hint, Oracle expands the in-lists condition into two query blocks, uses the index, and finally the concatenation gets the final output. -Note that the mandatory use of indexes here leads to a cost increase of 4. Statistics----------------------------------------------------------0 Recursive calls 0 DB block gets 4 consistent gets 0 Physical reads 0 Redo size 1032 Bytes sent via sql*net to client 655 bytes viaSql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 2 rows processedsql>
3.Oracle rewriting of execution plan
For inlist queries, Oracle typically overwrites the form
Select ... from ... where ..... in (............)
SQL statements, which are rewritten as union all to execute, and this rewrite is usually latent.
However, there may be a problem with this rewrite, and if there are more values in Inlist, the time and cost of the CBO in analyzing the execution path will be considerable, and we usually need to block Oracle's expansion.
We can prevent Oracle from making such a rewrite by No_expand hints.
So in fact, here, Use_concat and No_expand become reciprocal "inverse functions." After using the No_expand hint, Oracle uses "Inlist iterator" after Oracle8.
method to execute SQL so that you can use the index.
The author of this article:
Eygle,oracle technology concern, from China's largest Oracle technology forum Itpub.
Www.eygle.com is the author's personal site. You can contact the author by Guoqiang.Gai@gmail.com. Welcome technical discussions and exchange of links.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service