Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-13473

CONNECT BY: Does Oracle use depth-first or breadth-first traversal?

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Done
    • N/A
    • Optimizer
    • None

    Description

      A Followup to slack/zoom discussions:

      • Does Oracle use depth-first or breadth-first traversal?
      • Does it matter which we should use?

      Here's one way to check it: let's make a "logging function":

      create table tlog2(a int, num int);
      insert into tlog2 values (0,0);
       
      CREATE OR REPLACE
      FUNCTION f3
      ( param1 IN NUMBER
      ) RETURN NUMBER AS
      BEGIN
        insert into tlog2 values((select 1+ max(a) from tlog2), param1);
        RETURN param1;
      END f3;
      /
      

      sample dataset:

      create table employees (
        employee_id NUMBER,
        last_name varchar(32),
        manager_id  NUMBER
      );
       
      insert into employees values (201, 'team-red-freshman-1',181);
      insert into employees values (202, 'team-blue-freshman-1', 182);
       
      insert into employees values (181, 'team-red-l1', 161);
      insert into employees values (182, 'team-blue-11', 162);
       
      insert into employees values (161, 'team-red-l2', 141);
      insert into employees values (162, 'team-blue-12', 142);
       
      insert into employees values (141, 'team-red-l3', 121);
      insert into employees values (142, 'team-blue-13', 122);
       
      insert into employees values (121, 'team-red-l4', 100);
      insert into employees values (122, 'team-blue-14', 100);
       
      insert into employees values (100, 'ceo', 99);
      

      Oracle won't allow stored function to do DML if its a SELECT, so make it INSERT...SELECT:

      create table tdump3(
       col1 number,
       col2 varchar(32),
       col3 number
      );
      

      The query:

      insert into tdump3
      SELECT employee_id, last_name, manager_id
         FROM employees
         START WITH employee_id IN (201,202)
         CONNECT BY f3(PRIOR manager_id) = employee_id;
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.