Oracle Database Table join method: nested loop, sorting-merge, hash instance explanation, oracle instance explanation

Source: Internet
Author: User

Oracle Database Table join method: nested loop, sorting-merge, hash instance explanation, oracle instance explanation

Oracle Database Table join method: nested loop, sorting-merge, and hash

Nested loop: Generally, a small table is the driving table, and a large table is the driving table. The data that meets the conditions in a small table is traversed cyclically to find the data that meets the conditions. In general, an index on the condition column of a large table will speed up the query. Small tables are queried once, and large tables are scanned N times.

SQL> set autotrace traceonly;

SQL> select/* + leading (dept) use_nl (emp) */empno, dname, loc

From emp, dept

Where emp. deptno = dept. deptno; -- if the prompt is incorrect, the prompt is ignored.

Sort-merge: data is first sorted by the join key, and then the sorted data rows are merged. Data that cannot be sorted in memory may be sorted using a temporary disk space.

Both tables are accessed once. (Memory consumption)

SQL> set autotrace traceonly;

SQL> select/* + ordered use_merge (dept) */empno, dname, loc

From emp, dept

Where emp. deptno = dept. deptno; -- if the prompt is incorrect, the prompt is ignored.

Hash join: hash the tables that return the least rows to the memory by using the hash function, and then hash the joined columns in another table, if yes, this row of data is returned; otherwise, this row is discarded. Each table is accessed once. (Memory and CPU consumption)

SQL> set autotrace traceonly;

SQL> select/* + leading (emp) use_hash (dept) */empno, dname, loc

From emp, dept

Where emp. deptno = dept. deptno; -- if the prompt is incorrect, the prompt is ignored.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.