Skip to content

Commit

Permalink
Add oracle explain parse test
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaoAK47 committed Nov 19, 2023
1 parent 5de6944 commit 7fcca8e
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 0 deletions.
180 changes: 180 additions & 0 deletions test/it/parser/src/main/resources/case/dal/explain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,184 @@
</where>
</delete>
</describe>

<describe sql-case-id="explain_set_statement_id_with_select">
<select>
<projections start-index="68" stop-index="76">
<column-projection name="last_name" start-index="68" stop-index="76" />
</projections>
<from>
<simple-table name="employees" start-index="83" stop-index="91" />
</from>
</select>
</describe>

<describe sql-case-id="explain_set_statement_id_with_into_select1">
<select>
<projections start-index="109" stop-index="109">
<shorthand-projection start-index="109" stop-index="109" />
</projections>
<from>
<join-table join-type="COMMA">
<left>
<simple-table name="t" start-index="116" stop-index="116" />
</left>
<right>
<simple-table name="v" start-index="119" stop-index="119" />
</right>
</join-table>
</from>
<where start-index="121" stop-index="159">
<expr>
<binary-operation-expression start-index="127" stop-index="159">
<left>
<column name="department_id" start-index="127" stop-index="141">
<owner name="t" start-index="127" stop-index="127" />
</column>
</left>
<right>
<column name="department_id" start-index="145" stop-index="159">
<owner name="v" start-index="145" stop-index="145" />
</column>
</right>
<operator>=</operator>
</binary-operation-expression>
</expr>
</where>
</select>
<comment start-index="69" stop-index="93" text="/*+ LEADING(E@SEL$2 D@SEL$2 T@SEL$1) */" />
</describe>

<describe sql-case-id="explain_set_statement_id_with_into_select2">
<select>
<projections start-index="95" stop-index="95">
<shorthand-projection start-index="95" stop-index="95" />
</projections>
<from>
<join-table join-type="COMMA">
<left>
<simple-table name="t" start-index="102" stop-index="102" />
</left>
<right>
<simple-table name="v" start-index="105" stop-index="105" />
</right>
</join-table>
</from>
<where start-index="107" stop-index="145">
<expr>
<binary-operation-expression start-index="113" stop-index="145">
<left>
<column name="department_id" start-index="113" stop-index="127">
<owner name="t" start-index="113" stop-index="113" />
</column>
</left>
<right>
<column name="department_id" start-index="131" stop-index="145">
<owner name="v" start-index="131" stop-index="131" />
</column>
</right>
<operator>=</operator>
</binary-operation-expression>
</expr>
</where>
</select>
<comment start-index="69" stop-index="93" text="/*+ LEADING(v.e v.d t) */" />
</describe>

<describe sql-case-id="explain_set_statement_id_with_into_update">
<update>
<table start-index="76" stop-index="84">
<simple-table name="employees" start-index="76" stop-index="84" />
</table>
<set start-index="86" stop-index="111">
<assignment start-index="90" stop-index="111">
<column name="salary" start-index="90" stop-index="95" />
<assignment-value>
<binary-operation-expression start-index="99" stop-index="111">
<left>
<column name="salary" start-index="99" stop-index="104" />
</left>
<right>
<literal-expression value="1.10" start-index="108" stop-index="111" />
</right>
<operator>*</operator>
</binary-operation-expression>
</assignment-value>
</assignment>
</set>
<where start-index="113" stop-index="198">
<expr>
<binary-operation-expression start-index="119" stop-index="198">
<left>
<column name="department_id" start-index="119" stop-index="131" />
</left>
<right>
<subquery start-index="135" stop-index="198">
<select>
<projections start-index="143" stop-index="155">
<column-projection name="department_id" start-index="143" stop-index="155" />
</projections>
<from>
<simple-table name="departments" start-index="162" stop-index="172" />
</from>
<where start-index="174" stop-index="197">
<expr>
<binary-operation-expression start-index="180" stop-index="197">
<left>
<column name="location_id" start-index="180" stop-index="190" />
</left>
<operator>=</operator>
<right>
<literal-expression value="1700" start-index="194" stop-index="197" />
</right>
</binary-operation-expression>
</expr>
</where>
</select>
</subquery>
</right>
<operator>=</operator>
</binary-operation-expression>
</expr>
</where>
</update>
</describe>

<describe sql-case-id="explain_for_select_with_unique_partition_by">
<select>
<projections start-index="24" stop-index="49">
<column-projection name="country" start-index="24" stop-index="30" />
<column-projection name="prod" start-index="33" stop-index="36" />
<column-projection name="year" start-index="39" stop-index="42" />
<column-projection name="sales" start-index="45" stop-index="49" />
</projections>
<from>
<simple-table name="sales_view" start-index="56" stop-index="65" />
</from>
<where start-index="67" stop-index="101">
<expr>
<in-expression start-index="73" stop-index="101">
<not>false</not>
<left>
<column name="country" start-index="73" stop-index="79" />
</left>
<right>
<list-expression start-index="84" stop-index="101">
<items>
<literal-expression value="Italy" start-index="85" stop-index="91" />
</items>
<items>
<literal-expression value="Japan" start-index="94" stop-index="100" />
</items>
</list-expression>
</right>
</in-expression>
</expr>
</where>
<model start-index="103" stop-index="329">
<cell-assignment-column name="sales" start-index="215" stop-index="219" />
<cell-assignment-column name="sales" start-index="269" stop-index="273" />
</model>
</select>
</describe>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@
<sql-case id="explain_for_delete_statement" value="EXPLAIN PLAN SET STATEMENT_ID = 'insert1' FOR DELETE FROM t_order WHERE t_order.x = 1" db-types="Oracle" />
<sql-case id="explain_for_delete_into" value="EXPLAIN PLAN INTO t_order FOR DELETE FROM t_order WHERE t_order.x = 1" db-types="Oracle" />
<sql-case id="explain_for_delete_into_dblink" value="EXPLAIN PLAN INTO t_order@t_database.test_domain_name FOR DELETE FROM t_order WHERE t_order.x = 1" db-types="Oracle" />
<sql-case id="explain_set_statement_id_with_select" value="EXPLAIN PLAN SET STATEMENT_ID = 'st1' INTO my_plan_table FOR SELECT last_name FROM employees" db-types="Oracle" />
<sql-case id="explain_set_statement_id_with_into_select1" value="EXPLAIN PLAN SET STATEMENT_ID = 'Test 2' INTO plan_table FOR (SELECT /*+ LEADING(E@SEL$2 D@SEL$2 T@SEL$1) */ * FROM t, v WHERE t.department_id = v.department_id)" db-types="Oracle" />
<sql-case id="explain_set_statement_id_with_into_select2" value="EXPLAIN PLAN SET STATEMENT_ID = 'Test 1' INTO plan_table FOR (SELECT /*+ LEADING(v.e v.d t) */ * FROM t, v WHERE t.department_id = v.department_id)" db-types="Oracle" />
<sql-case id="explain_set_statement_id_with_into_update" value="EXPLAIN PLAN SET STATEMENT_ID = 'Raise in Tokyo' INTO plan_table FOR UPDATE employees SET salary = salary * 1.10 WHERE department_id = (SELECT department_id FROM departments WHERE location_id = 1700)" db-types="Oracle" />
<sql-case id="explain_for_select_with_unique_partition_by" value="EXPLAIN PLAN FOR SELECT country, prod, year, sales FROM sales_view WHERE country IN ('Italy', 'Japan') MODEL UNIQUE DIMENSION PARTITION BY (country) DIMENSION BY (prod, year)
MEASURES (sale sales) RULES UPSERT (sales['Bounce', 2003] = AVG(sales)[ANY, 2002] * 1.24, sales[prod &lt;&gt; 'Bounce', 2003] = sales['Bounce', 2003] * 0.25)" db-types="Oracle" />
</sql-cases>

0 comments on commit 7fcca8e

Please sign in to comment.