Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I always try to put the expressions in <code>JOIN</code>'s in the following order:</p> <pre><code>joined.column = leading.column </code></pre> <p>This query:</p> <pre><code>SELECT t.value, d.name FROM transactions t JOIN dimensions d ON d.id = t.dimension </code></pre> <p>can be treated either like "for each transaction, find the corresponding dimension name", or "for each dimension, find all corresponding transaction values".</p> <p>So, if I search for a given transaction, I put the expressions in the following order:</p> <pre><code>SELECT t.value, d.name FROM transactions t JOIN dimensions d ON d.id = t.dimension WHERE t.id = :myid </code></pre> <p>, and if I search for a dimension, then:</p> <pre><code>SELECT t.value, d.name FROM dimensions d JOIN transactions t ON t.dimension = d.id WHERE d.id = :otherid </code></pre> <p>Ther former query will most probably use index scans first on <code>(t.id)</code>, then on (<code>d.id</code>), while the latter one will use index scans first on <code>(d.id)</code>, then on <code>(t.dimension)</code>, and you can easily see it in the query itself: the searched fields are at left.</p> <p>The driving and driven tables may be not so obvious in a <code>JOIN</code>, but it's as clear as a bell for a <code>CONNECT BY</code> query: the <code>PRIOR</code> row is driving, the non-<code>PRIOR</code> is driven.</p> <p>That's why this query:</p> <pre><code>SELECT * FROM hierarchy START WITH id = :root CONNECT BY parent = PRIOR id </code></pre> <p>means "find all rows whose <code>parent</code> is a given <code>id</code>". This query builds a hierarchy.</p> <p>This can be treated like this:</p> <pre><code>connect_by(row) { add_to_rowset(row); /* parent = PRIOR id */ /* PRIOR id is an rvalue */ index_on_parent.searchKey = row-&gt;id; foreach child_row in index_on_parent.search { connect_by(child_row); } } </code></pre> <p>And this query:</p> <pre><code>SELECT * FROM hierarchy START WITH id = :leaf CONNECT BY id = PRIOR parent </code></pre> <p>means "find the rows whose <code>id</code> is a given <code>parent</code>". This query builds an ancestry chain.</p> <p><strong>Always put <code>PRIOR</code> in the right part of the expression.</strong></p> <p><strong>Think of <code>PRIOR column</code> as of a constant all your rows will be searched for.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload