AQL teaser 2 for implementers

Dear implementers:
@bna @matijap @ian.mcnicoll

Given the composition on the left, and the AQL query after that, what should the result set for the select clause on the right be? Same as before: think on it whenever you have some free time

SELECT
    c,s,i_1,i_2
FROM
    COMPOSITION C c
        CONTAINS
    SECTION s
        CONTAINS 
    (INSTRUCTION i_1 AND INSTRUCTION i_2)

<c|s|i|i|i>(i) on the leftmost tree is composition|section|instruction(x3) instances, i.e. a single composition instance.

If I argued collapsing results into as few rows as possible (while still having a characteristic of a cartesian product), I will with even more confidence proclaim that is the correct way in case of conjunction. This is exactly like SQL inner join with a condition that i_1 != i_2.

sorry @matijap I understand your point but can’t understand how you suggest that point could be applied to this example.
do you mean you’d collapse rows that are permutations of the same set ([i1,i2], [i2,i1]) ?

Yes, and I’ll edit my previous message comparing this to inner join: there is a subtle difference that the instructions are never the exact same object; there need to be two instructions.

Oh, I’m sorry, I didn’t read the question clearly enough; I see you are asking about a result on a composition with 3 instructions, and in this case you’ll get 6 rows (3x3=9, minus the 3 cases where both variables bind to the same object).

My explanation for removing those is “an object cannot be in two columns of a row at the same time”, since merely having two variables implies having two different instances of data :slight_smile: Glad to agree on yet another one.

We agree on what having two variables implies. You could, however, use the same variable multiple times in the projection in a way that would cause having “an object in two rows”. Or indeed you could have different variables between which there is containment, and it’s actually what bothers Pablo, but I say you can have the same field in the projection as many times you like. :slight_smile:

absolutely. My statement is based on “a row”. Completely agree with the rest of your statement

I meant columns, of course, but I think you understood that.

no , I did not read it carefully it appears :slight_smile: but I think you’re referring to SELECT reusing an alias/variable from alias multiple times, in which case, I’d certainly agree.

1 Like

This is the permutation problem - again :slight_smile:
The result-set will have 3 x 3 = 9 rows.

image

The executed AQL was:

SELECT
   c/name/value as C1,
   s/name/value as S1,
   i_1/name/value as I1,
   i_2/name/value as I2
FROM
COMPOSITION c
    CONTAINS SECTION s
        CONTAINS (
        INSTRUCTION i_1 AND INSTRUCTION i_2
        )