Oracle recursive performance prompt

Source: Internet
Author: User

When you use start with connect by nocycle prior

When performing recursive data search

So the performance of the following two sections of code must be significantly different when you use it, please note that the code can be directly read below to view my summary

// Query the number of layers in a folder ID = 12 and the number of files

A: indicates the parent-subordinate relationship between files.

B: The file in the folder.

Positive Solution:

Select count (0) cou, max (levels) + 1 as levels

Select C. a1, C. a2, C. levels...

From

(Select A. a1, A. a2 ,,,

Level levels // hierarchy

From

Where A. a1 = ,,,

And A. a2 = ....

Start with A. a1 = 12

Connect by nocylce prior A. ID = A. ParentID

) C left join B

On C. File ID = B. File ID

And C. file type = folder

Error code:

Select count (0) cou, max (levels) + 1 as levels

Select C. a1, C. a2, C. levels...

From

(Select A. a1, A. a2 ,,,

Level levels // hierarchy

From

Left join B

On C. File ID = B. File ID

Where C. file type = folder

And A. a1 = ,,,

And A. a2 = ....

Start with A. a1 = 12

Connect by nocylce prior A. ID = A. ParentID

) C

The difference between the above Code is that

The correct method is:

Recursively loop all the folders and files under a folder

Search for the file content in the associated file table

The error is:

First, find the folder and file under a folder.

Then recursively loop out all the folders and files in the folder below him.

In this way, the redundant data after Association is generated. Loop recursion is performed together. It has nothing to do with the file. Shouldn't it? The file is also put in recursion.

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.