Merge lp:~mmcm/akiban-server/sql-in-subquery-wo-project into lp:~akiban-technologies/akiban-server/trunk

Proposed by Mike McMahon
Status: Merged
Approved by: Nathan Williams
Approved revision: 2732
Merged at revision: 2732
Proposed branch: lp:~mmcm/akiban-server/sql-in-subquery-wo-project
Merge into: lp:~akiban-technologies/akiban-server/trunk
Diff against target: 57 lines (+26/-0)
4 files modified
src/main/java/com/akiban/sql/optimizer/rule/ASTStatementLoader.java (+13/-0)
src/test/resources/com/akiban/sql/optimizer/rule/parse/README.txt (+2/-0)
src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.expected (+9/-0)
src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.sql (+2/-0)
To merge this branch: bzr merge lp:~mmcm/akiban-server/sql-in-subquery-wo-project
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Review via email: mp+179053@code.launchpad.net

Description of the change

Handle subquery predicates with VALUES.

IN (1,2) is a special kind of node.
IN (SELECT x FROM ...) has a Project which is used to extract the comparison operand for the semi-join.
IN (VALUES 1,2) is somewhere in between. The Project isn't there, but enough information is to form the identical plan to the first case. Add that.

See new test and note that the expected result is identical to in-l3.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

Simple enough.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main/java/com/akiban/sql/optimizer/rule/ASTStatementLoader.java'
2--- src/main/java/com/akiban/sql/optimizer/rule/ASTStatementLoader.java 2013-07-31 20:40:42 +0000
3+++ src/main/java/com/akiban/sql/optimizer/rule/ASTStatementLoader.java 2013-08-07 21:31:27 +0000
4@@ -926,6 +926,19 @@
5 plan = next;
6 }
7 }
8+ if ((operands == null) &&
9+ (subquery instanceof ColumnSource) &&
10+ (subquery instanceof TypedPlan)) {
11+ int nfields = ((TypedPlan)subquery).nFields();
12+ if (!multipleOperands && (nfields != 1))
13+ throw new UnsupportedSQLException("Subquery must have exactly one column", subqueryNode);
14+ operands = new ArrayList<>(nfields);
15+ for (int i = 0; i < nfields; i++) {
16+ operands.add(new ColumnExpression(((ColumnSource)subquery), i, null, null));
17+ }
18+ if (nfields > 0)
19+ operand = operands.get(0);
20+ }
21 ConditionExpression condition;
22 if (needOperand) {
23 assert (operand != null);
24
25=== modified file 'src/test/resources/com/akiban/sql/optimizer/rule/parse/README.txt'
26--- src/test/resources/com/akiban/sql/optimizer/rule/parse/README.txt 2013-07-31 20:41:01 +0000
27+++ src/test/resources/com/akiban/sql/optimizer/rule/parse/README.txt 2013-08-07 21:31:27 +0000
28@@ -76,6 +76,8 @@
29
30 in-4: IN with row value subquery
31
32+in-5: IN with VALUES (explicitly as subquery)
33+
34 insert-1: from VALUES
35
36 insert-2: from SELECT
37
38=== added file 'src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.expected'
39--- src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.expected 1970-01-01 00:00:00 +0000
40+++ src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.expected 2013-08-07 21:31:27 +0000
41@@ -0,0 +1,9 @@
42+SelectQuery@6e92b1a1
43+ ResultSet@68c0890f[cid, name]
44+ Project@38666d83[customers.cid, customers.name]
45+ Select@6f7918f0[ANY(Subquery@40b86944)]
46+ TableSource@47f08ed8(customers)
47+
48+Subquery@40b86944
49+ Project@3ab28980[customers.name == VALUES[0]]
50+ ExpressionsSource@2322bce([[Smith], [Jones], [Adams]])
51
52=== added file 'src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.sql'
53--- src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.sql 1970-01-01 00:00:00 +0000
54+++ src/test/resources/com/akiban/sql/optimizer/rule/parse/in-5.sql 2013-08-07 21:31:27 +0000
55@@ -0,0 +1,2 @@
56+SELECT * FROM customers
57+ WHERE name IN (VALUES('Smith'), ('Jones'), ('Adams'))

Subscribers

People subscribed via source and target branches