Skip to content

Adding more complete support for set operations: UNION / INTERSECT / …#84

Closed
javrucebo wants to merge 5 commits intohyrise:masterfrom
javrucebo:set-operations
Closed

Adding more complete support for set operations: UNION / INTERSECT / …#84
javrucebo wants to merge 5 commits intohyrise:masterfrom
javrucebo:set-operations

Conversation

@javrucebo
Copy link
Copy Markdown
Contributor

Adding more complete support for set operations: UNION / INTERSECT / EXCEPT

Allow multiple operations, differentiate between the operators, honor parentheses

  • internal data structure is changing. Instead of the unionSelect pointer
    to a second SelectStatement two new vectors as members of
    SelectStatement are introduced:

    • setStatement: holds pointers to SelectStatement(s) right of first
      set operation

    • setType: holds pointers to new struct SetDescription with members

      • type: Enum (kSetUnion, kSetIntersect, kSetExcept)
      • all: bool to indicate if keyword ALL was used
  • if no parentheses are used then there is only one set of vectors, e.g. for
    SELECT a1 FROM t1 UNION SELECT a2 FROM t2 EXCEPT ALL SELECT a3 FROM t3
    then setStatement holds two SelectStatements

SelectStatement
   Table t1
   ColumnRef a1
   setStatement
      SelectStatement
        Table t2
        ColumnRef a2
      SelectStatement
        Table t3
        ColumnRef a3
   setType
      SetDescription
        type kSetUnion
        all false
      SetDescription
        type kSetExcept
        all true
  • if parentheses are used then nested structure is built e.g. for
    SELECT a1 FROM t1 UNION (SELECT a2 FROM t2 EXCEPT ALL SELECT a3 FROM t3)
  SelectStatement
    Table t1
    ColumnRef a1
    setStatement
       SelectStatement
         Table t2
         ColumnRef a2
         setStatement
           SelectStatement
             Table t3
             ColumnRef a3
         setType
           SetDescription
             type kSetExcept
             all true
    setType
      SetDescription
        type kSetUnion
        all false

…EXCEPT

Allow multiple operations, differentiate between the operators, honor parentheses

- internal data structure is changing. Instead of the `unionSelect` pointer
  to a second SelectStatement two new vectors as members of
  SelectStatement are introduced:

  - setStatement: holds pointers to SelectStatement(s) right of first
    set operation

  - setType: holds pointers to new struct SetDescription with members
    - type: Enum (kSetUnion, kSetIntersect, kSetExcept)
    - all: bool to indicate if keyword ALL was used

- if no parentheses are used then there is only one set of vectors, e.g. for
  SELECT a1 FROM t1 UNION SELECT a2 FROM t2 EXCEPT ALL SELECT a3 FROM t3
  then setStatement holds two SelectStatements
  SelectStatement
    Table t1
    ColumnRef a1
    setStatement
       SelectStatement
         Table t2
         ColumnRef a2
       SelectStatement
         Table t3
         ColumnRef a3
    setType
       SetDescription
         type kSetUnion
         all false
       SetDescription
         type kSetExcept
         all true

- if parentheses are used then nested structure is built e.g. for
  SELECT a1 FROM t1 UNION (SELECT a2 FROM t2 EXCEPT ALL SELECT a3 FROM t3)
  SelectStatement
    Table t1
    ColumnRef a1
    setStatement
       SelectStatement
         Table t2
         ColumnRef a2
         setStatement
           SelectStatement
             Table t3
             ColumnRef a3
         setType
           SetDescription
             type kSetExcept
             all true
    setType
      SetDescription
        type kSetUnion
        all false
Comment thread src/sql/statements.cpp Outdated
}
}

SelectStatement* MakeOrAppendUnionList(SelectStatement* stmt,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not only a UnionList, is it? Maybe MakeOrAppendSetList?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed to MakeOrAppendSetList as suggested

Comment thread test/select_tests.cpp
TEST(SetOperations) {
SelectStatement* stmt;

TEST_PARSE_SQL_QUERY("select a from t1 union select b from t2; \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit/order after set operations should probably included here? As in "SELECT a FROM t1 UNION (...) ORDER BY a LIMIT 5"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added such tests for WHERE/LIMIT/ORDER as suggested

@mrzzzrm
Copy link
Copy Markdown

mrzzzrm commented Feb 8, 2018

The SELECT statement grammar could really use some doc or better names, but that's not your concern. The setType/setStatement architecture is a bit confusing (especially since "set" is such an ambiguous word) but I can see why you would use it. I guess if we increase the testing as requested this should be fine.

@javrucebo
Copy link
Copy Markdown
Contributor Author

I agree the naming could be confusing. Happy to change if you have other suggestion. As you pointed out I chose naming as those are operations on sets.

@mweisgut
Copy link
Copy Markdown
Contributor

mweisgut commented Jan 6, 2022

Closing this issue since it is outdated. In the meantime, #138 already added additional set operations support.

@mweisgut mweisgut closed this Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants