Changeset: 9f1b435638d6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f1b435638d6
Modified Files:
        sql/server/rel_select.c
        sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
        sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.stable.out
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
        
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
        sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: Oct2020
Log Message:

allow select * (select 1 a, 2 a)


diffs (242 lines):

diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -5116,8 +5116,24 @@ column_exp(sql_query *query, sql_rel **r
        return ve;
 }
 
+static int
+exp_is_not_intern(sql_exp *e)
+{
+       return is_intern(e)?-1:0;
+}
+
+static void
+rel_remove_internal_exp(sql_rel *rel)
+{
+       if (rel->exps) {
+               list *n_exps = list_select(rel->exps, rel, 
(fcmp)&exp_is_not_intern, (fdup)NULL);
+
+               rel->exps = n_exps;
+       }
+}
+
 static list *
-rel_table_exp(sql_query *query, sql_rel **rel, symbol *column_e )
+rel_table_exp(sql_query *query, sql_rel **rel, symbol *column_e, bool 
single_exp )
 {
        mvc *sql = query->sql;
        if (column_e->token == SQL_TABLE && column_e->data.lval->h->type == 
type_symbol) {
@@ -5132,7 +5148,7 @@ rel_table_exp(sql_query *query, sql_rel 
                return sa_list(sql->sa);
        } else if (column_e->token == SQL_TABLE) {
                char *tname = column_e->data.lval->h->data.sval;
-               list *exps;
+               list *exps = NULL;
                sql_rel *project = *rel, *groupby = NULL;
 
                /* if there's a group by relation in the tree, skip it for the 
'*' case and use the underlying projection */
@@ -5146,7 +5162,12 @@ rel_table_exp(sql_query *query, sql_rel 
                        assert(project);
                }
 
-               if ((exps = rel_table_projections(sql, project, tname, 0)) != 
NULL && !list_empty(exps)) {
+               if (project->op == op_project && project->l && project == *rel 
&& !tname && !rel_is_ref(project) && !need_distinct(project) && single_exp) {
+                       rel_remove_internal_exp(*rel);
+                       exps = project->exps;
+                       *rel = project->l;
+               }
+               if ((exps || (exps = rel_table_projections(sql, project, tname, 
0)) != NULL) && !list_empty(exps)) {
                        if (groupby) {
                                groupby->exps = 
list_distinct(list_merge(groupby->exps, exps, (fdup) NULL), (fcmp) exp_equal, 
(fdup) NULL);
                                for (node *n = groupby->exps->h ; n ; n = 
n->next) {
@@ -5383,22 +5404,6 @@ join_on_column_name(sql_query *query, sq
        return rel;
 }
 
-static int
-exp_is_not_intern(sql_exp *e)
-{
-       return is_intern(e)?-1:0;
-}
-
-static void
-rel_remove_internal_exp(sql_rel *rel)
-{
-       if (rel->exps) {
-               list *n_exps = list_select(rel->exps, rel, 
(fcmp)&exp_is_not_intern, (fdup)NULL);
-
-               rel->exps = n_exps;
-       }
-}
-
 static sql_rel *
 rel_select_exp(sql_query *query, sql_rel *rel, SelectNode *sn, exp_kind ek)
 {
@@ -5433,7 +5438,7 @@ rel_select_exp(sql_query *query, sql_rel
                        rel = inner;
                        continue;
                } else if (!ce) {
-                       te = rel_table_exp(query, &rel, n->data.sym);
+                       te = rel_table_exp(query, &rel, n->data.sym, 
!list_length(pexps) && !n->next);
                } else
                        ce = NULL;
                if (!ce && !te) {
diff --git 
a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out 
b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
--- a/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
+++ b/sql/test/BugTracker-2013/Tests/duplicate_column_name.Bug-3349.stable.out
@@ -41,8 +41,8 @@ stdout of test 'duplicate_column_name.Bu
 % int, int,    int,    int # type
 % 1,   1,      1,      1 # length
 [ 1,   1,      1,      1       ]
-[ 1,   1,      1,      1       ]
-[ 1,   2,      1,      2       ]
+[ 1,   1,      1,      2       ]
+[ 1,   2,      1,      1       ]
 [ 1,   2,      1,      2       ]
 #SELECT *
 #FROM (
diff --git a/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.stable.out 
b/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.stable.out
--- a/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.stable.out
+++ b/sql/test/BugTracker-2016/Tests/merge_project.Bug-3955.stable.out
@@ -59,28 +59,26 @@ stdout of test 'merge_project.Bug-3955` 
 % .plan # table_name
 % rel # name
 % clob # type
-% 107 # length
+% 105 # length
 project (
-| project (
-| | crossproduct (
-| | | table(sys.v) [ "v"."a1", "v"."a2" ] COUNT ,
-| | | project (
-| | | | crossproduct (
-| | | | | project (
-| | | | | | select (
-| | | | | | | table(sys.input_double) [ "input_double"."a1", 
"input_double"."a2" ] COUNT 
-| | | | | | ) [ "input_double"."a1" = clob "latitude" ]
-| | | | | ) [ "input_double"."a2" as "tmp_2"."a2" ],
-| | | | | project (
-| | | | | | select (
-| | | | | | | table(sys.input_double) [ "input_double"."a1", 
"input_double"."a2" ] COUNT 
-| | | | | | ) [ "input_double"."a1" = clob "longitude" ]
-| | | | | ) [ "input_double"."a2" as "tmp_3"."a2" ]
-| | | | ) [  ]
-| | | ) [ sys.st_point("tmp_2"."a2" as "tmp"."a1", "tmp_3"."a2" as "tmp"."a2") 
as "p"."a1" ]
-| | ) [  ]
-| ) [ "v"."a1" as "r"."a1", sys.st_distance("v"."a2" as "tmp"."a2", "p"."a1" 
as "tmp"."a3") as "r"."prob" ]
-) [ "r"."a1", "r"."prob" ]
+| crossproduct (
+| | table(sys.v) [ "v"."a1", "v"."a2" ] COUNT ,
+| | project (
+| | | crossproduct (
+| | | | project (
+| | | | | select (
+| | | | | | table(sys.input_double) [ "input_double"."a1", "input_double"."a2" 
] COUNT 
+| | | | | ) [ "input_double"."a1" = clob "latitude" ]
+| | | | ) [ "input_double"."a2" as "tmp_2"."a2" ],
+| | | | project (
+| | | | | select (
+| | | | | | table(sys.input_double) [ "input_double"."a1", "input_double"."a2" 
] COUNT 
+| | | | | ) [ "input_double"."a1" = clob "longitude" ]
+| | | | ) [ "input_double"."a2" as "tmp_3"."a2" ]
+| | | ) [  ]
+| | ) [ sys.st_point("tmp_2"."a2" as "tmp"."a1", "tmp_3"."a2" as "tmp"."a2") 
as "p"."a1" ]
+| ) [  ]
+) [ "v"."a1" as "r"."a1", sys.st_distance("v"."a2" as "tmp"."a2", "p"."a1" as 
"tmp"."a3") as "r"."prob" ]
 
 # 14:00:10 >  
 # 14:00:10 >  "Done."
diff --git 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
--- 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
+++ 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
@@ -37,7 +37,7 @@ function user.main():void;
     X_4:int := sql.mvc();
     C_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "fk":str);
     X_23:lng := aggr.count(C_5:bat[:oid]);
-    sql.resultSet(".%4":str, "%4":str, "bigint":str, 64:int, 0:int, 7:int, 
X_23:lng);
+    sql.resultSet(".%3":str, "%3":str, "bigint":str, 64:int, 0:int, 7:int, 
X_23:lng);
 end user.main;
 #inline               actions= 0 time=1 usec 
 #remap                actions= 0 time=2 usec 
diff --git 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
--- 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
+++ 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
@@ -37,7 +37,7 @@ function user.main():void;
     X_4:int := sql.mvc();
     C_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "fk":str);
     X_23:lng := aggr.count(C_5:bat[:oid]);
-    sql.resultSet(".%6":str, "%6":str, "bigint":str, 64:int, 0:int, 7:int, 
X_23:lng);
+    sql.resultSet(".%5":str, "%5":str, "bigint":str, 64:int, 0:int, 7:int, 
X_23:lng);
 end user.main;
 #inline               actions= 0 time=0 usec 
 #remap                actions= 0 time=1 usec 
diff --git 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
--- 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
+++ 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
@@ -35,8 +35,8 @@ stdout of test 'foreign_key_outer_join_d
 project (
 | group by (
 | | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL  ] COUNT 
-| ) [  ] [ sys.count() NOT NULL as "%4"."%4" ]
-) [ "%4"."%4" NOT NULL ]
+| ) [  ] [ sys.count() NOT NULL as "%3"."%3" ]
+) [ "%3"."%3" NOT NULL ]
 #plan select id       from v1 order by id;
 % .plan # table_name
 % rel # name
diff --git 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
--- 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
+++ 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
@@ -35,8 +35,8 @@ stdout of test 'foreign_key_outer_join_d
 project (
 | group by (
 | | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL  ] COUNT 
-| ) [  ] [ sys.count() NOT NULL as "%6"."%6" ]
-) [ "%6"."%6" NOT NULL ]
+| ) [  ] [ sys.count() NOT NULL as "%5"."%5" ]
+) [ "%5"."%5" NOT NULL ]
 #plan select id       from v2 order by id;
 % .plan # table_name
 % rel # name
diff --git 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
--- 
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
+++ 
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
@@ -176,8 +176,8 @@ stdout of test 'foreign_key_outer_join_d
 % 1 # length
 [ 6    ]
 #select count(*) from v1;
-% .%4 # table_name
-% %4 # name
+% .%3 # table_name
+% %3 # name
 % bigint # type
 % 1 # length
 [ 6    ]
@@ -188,8 +188,8 @@ stdout of test 'foreign_key_outer_join_d
 % 1 # length
 [ 6    ]
 #select count(*) from v2;
-% .%6 # table_name
-% %6 # name
+% .%5 # table_name
+% %5 # name
 % bigint # type
 % 1 # length
 [ 6    ]
diff --git a/sql/test/miscellaneous/Tests/simple_selects.stable.out 
b/sql/test/miscellaneous/Tests/simple_selects.stable.out
--- a/sql/test/miscellaneous/Tests/simple_selects.stable.out
+++ b/sql/test/miscellaneous/Tests/simple_selects.stable.out
@@ -380,6 +380,12 @@ stdout of test 'simple_selects` in direc
 % int, int,    varchar,        varchar # type
 % 1,   1,      0,      0 # length
 #rollback;
+#select * from (select 1 as c0, 2 as c0) as sub;
+% .sub,        .sub # table_name
+% c0,  c0 # name
+% tinyint,     tinyint # type
+% 1,   1 # length
+[ 1,   2       ]
 
 # 17:31:38 >  
 # 17:31:38 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to