Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PL/SQL: subquery_operation_part in atom #4348

Open
n9 opened this issue Dec 4, 2024 · 1 comment
Open

PL/SQL: subquery_operation_part in atom #4348

n9 opened this issue Dec 4, 2024 · 1 comment
Labels

Comments

@n9
Copy link

n9 commented Dec 4, 2024

PL/SQL atom currently allows subquery to be followed by subquery_operation_part after ):

| '(' subquery ')' subquery_operation_part*

Is this correct? If so, where is it documented?

This "addition" comes from this commit: porcelli/plsql-parser@1b9a348. And the test file included in that commit passes the current grammar without the "extra" subquery_operation_part.

@kaby76
Copy link
Contributor

kaby76 commented Dec 4, 2024

Yes, that is also a source of ambiguity. For union10.sql, the ambiguity trees are:

subquery.sql.d=2441.a=5: (sql_script (unit_statement (data_manipulation_language_statements (select_statement (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (LEFT_PAREN "(") (subquery (subquery_basic_elements (LEFT_PAREN "(") (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (CHAR_STRING "'y'"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (quantified_expression (EXISTS "exists") (LEFT_PAREN "(") (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))) (relational_operator (EQUALS_OP "=")) (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "0")))))))))))))))))))) (RIGHT_PAREN ")")))))))))))))))) (RIGHT_PAREN ")")) (subquery_operation_part (UNION "union") (subquery_basic_elements (LEFT_PAREN "(") (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (CHAR_STRING "'n'"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (NOT "not") (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (quantified_expression (EXISTS "exists") (LEFT_PAREN "(") (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))) (relational_operator (EQUALS_OP "=")) (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "0")))))))))))))))))))) (RIGHT_PAREN ")")))))))))))))))) (RIGHT_PAREN ")")))) (RIGHT_PAREN ")"))))))))))) (column_alias (AS "as") (identifier (id_expression (regular_id (REGULAR_ID "yes_no"))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual")))))))))))))))))) (EOF ""))
subquery.sql.d=2441.a=6: (sql_script (unit_statement (data_manipulation_language_statements (select_statement (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (LEFT_PAREN "(") (expressions (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (LEFT_PAREN "(") (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (CHAR_STRING "'y'"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (quantified_expression (EXISTS "exists") (LEFT_PAREN "(") (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))) (relational_operator (EQUALS_OP "=")) (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "0")))))))))))))))))))) (RIGHT_PAREN ")")))))))))))))))) (RIGHT_PAREN ")") (subquery_operation_part (UNION "union") (subquery_basic_elements (LEFT_PAREN "(") (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (CHAR_STRING "'n'"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (NOT "not") (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (quantified_expression (EXISTS "exists") (LEFT_PAREN "(") (select_only_statement (subquery (subquery_basic_elements (query_block (SELECT "select") (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual"))))))))))) (where_clause (WHERE "where") (condition (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "1"))))))))) (relational_operator (EQUALS_OP "=")) (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric (UNSIGNED_INTEGER "0")))))))))))))))))))) (RIGHT_PAREN ")")))))))))))))))) (RIGHT_PAREN ")")))))))))))))) (RIGHT_PAREN ")"))))))))))) (column_alias (AS "as") (identifier (id_expression (regular_id (REGULAR_ID "yes_no"))))))) (from_clause (FROM "from") (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id (REGULAR_ID "dual")))))))))))))))))) (EOF ""))

Without the "extra" subquery_operation_part*, there's no ambiguity for the test case. And the entire test suite passes. With the change, performance improves as well. With the change, the test suite takes ~20s as opposed to ~24s with the "extra".

@KvanTTT KvanTTT added the plsql label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants