Changeset: 131cab11330e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=131cab11330e Modified Files: sql/server/rel_exp.c sql/server/rel_select.c sql/test/miscellaneous/Tests/simple_plans.sql sql/test/miscellaneous/Tests/simple_plans.stable.out sql/test/miscellaneous/Tests/simple_plans.stable.out.single Branch: octbugs Log Message:
Look for common ordering expressions and cleanup diffs (107 lines): diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c --- a/sql/server/rel_exp.c +++ b/sql/server/rel_exp.c @@ -1293,8 +1293,9 @@ exp_match_exp( sql_exp *e1, sql_exp *e2) { if (exp_match(e1, e2)) return 1; - if (e1->ascending != e2->ascending || e1->nulls_last != e2->nulls_last || e1->zero_if_empty != e2->zero_if_empty || - e1->anti != e2->anti || e1->semantics != e2->semantics || e1->distinct != e2->distinct) + if (is_ascending(e1) != is_ascending(e2) || nulls_last(e1) != nulls_last(e2) || zero_if_empty(e1) != zero_if_empty(e2) || + need_no_nil(e1) != need_no_nil(e2) || is_anti(e1) != is_anti(e2) || is_semantics(e1) != is_semantics(e2) || + need_distinct(e1) != need_distinct(e2)) return 0; if (e1->type == e2->type) { switch(e1->type) { 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 @@ -4224,7 +4224,7 @@ rel_order_by(sql_query *query, sql_rel * if (order->token == SQL_COLUMN || order->token == SQL_IDENT) { symbol *col = order->data.lval->h->data.sym; int direction = order->data.lval->h->next->data.i_val; - sql_exp *e = NULL; + sql_exp *e = NULL, *oe = NULL; assert(order->data.lval->h->next->type == type_int); if ((selection = simple_selection(col)) != NULL) { @@ -4279,13 +4279,12 @@ rel_order_by(sql_query *query, sql_rel * if (!e) e = rel_order_by_column_exp(query, &rel, col, sql_sel | sql_orderby | (f & sql_group_totals)); - if (e && e->card > rel->card && e->card != CARD_ATOM) - e = NULL; } if (!e) return NULL; set_direction(e, direction); - append(exps, e); + if (!(oe = exps_any_match_same_or_no_alias(exps, e)) || is_ascending(oe) != is_ascending(e) || nulls_last(oe) != nulls_last(e)) + list_append(exps, e); } else { return sql_error(sql, 02, SQLSTATE(42000) "SELECT: order not of type SQL_COLUMN"); } diff --git a/sql/test/miscellaneous/Tests/simple_plans.sql b/sql/test/miscellaneous/Tests/simple_plans.sql --- a/sql/test/miscellaneous/Tests/simple_plans.sql +++ b/sql/test/miscellaneous/Tests/simple_plans.sql @@ -4,6 +4,8 @@ create table myy (col1 int, col2 int); insert into myy values (1, 1), (2, 0), (3,3), (4,2); select distinct col1 + col2 from myy order by col1 + col2; plan select distinct col1 + col2 from myy order by col1 + col2; +plan select col2 from myy order by col1 ASC, col1 DESC; +plan select col2 from myy order by col1 DESC, col1 DESC; create table myx (x uuid, y uuid); plan select * from myx where x in ('1aea00e5db6e0810b554fde31d961965') or y = '1aea00e5db6e0810b554fde31d961965'; diff --git a/sql/test/miscellaneous/Tests/simple_plans.stable.out b/sql/test/miscellaneous/Tests/simple_plans.stable.out --- a/sql/test/miscellaneous/Tests/simple_plans.stable.out +++ b/sql/test/miscellaneous/Tests/simple_plans.stable.out @@ -28,6 +28,22 @@ project ( | | ) [ sys.sql_add(bigint["myy"."col1"] as "myy"."col1", bigint["myy"."col2"] as "myy"."col2") as "%1"."%1" ] | ) [ "%1"."%1" ] [ "%1"."%1" ] ) [ "%1"."%1" ] [ "%1"."%1" ASC ] +#plan select col2 from myy order by col1 ASC, col1 DESC; +% .plan # table_name +% rel # name +% clob # type +% 64 # length +project ( +| table(sys.myy) [ "myy"."col1", "myy"."col2" ] COUNT +) [ "myy"."col2" ] [ "myy"."col1" ASC, "myy"."col1" NULLS LAST ] +#plan select col2 from myy order by col1 DESC, col1 DESC; +% .plan # table_name +% rel # name +% clob # type +% 54 # length +project ( +| table(sys.myy) [ "myy"."col1", "myy"."col2" ] COUNT +) [ "myy"."col2" ] [ "myy"."col1" NULLS LAST ] #create table myx (x uuid, y uuid); #plan select * from myx where x in ('1aea00e5db6e0810b554fde31d961965') or y = '1aea00e5db6e0810b554fde31d961965'; % .plan # table_name diff --git a/sql/test/miscellaneous/Tests/simple_plans.stable.out.single b/sql/test/miscellaneous/Tests/simple_plans.stable.out.single --- a/sql/test/miscellaneous/Tests/simple_plans.stable.out.single +++ b/sql/test/miscellaneous/Tests/simple_plans.stable.out.single @@ -28,6 +28,22 @@ project ( | | ) [ sys.sql_add(bigint["myy"."col1"] as "myy"."col1", bigint["myy"."col2"] as "myy"."col2") as "%1"."%1" ] | ) [ "%1"."%1" ] [ "%1"."%1" ] ) [ "%1"."%1" ] [ "%1"."%1" ASC ] +#plan select col2 from myy order by col1 ASC, col1 DESC; +% .plan # table_name +% rel # name +% clob # type +% 64 # length +project ( +| table(sys.myy) [ "myy"."col1", "myy"."col2" ] COUNT +) [ "myy"."col2" ] [ "myy"."col1" ASC, "myy"."col1" NULLS LAST ] +#plan select col2 from myy order by col1 DESC, col1 DESC; +% .plan # table_name +% rel # name +% clob # type +% 54 # length +project ( +| table(sys.myy) [ "myy"."col1", "myy"."col2" ] COUNT +) [ "myy"."col2" ] [ "myy"."col1" NULLS LAST ] #create table myx (x uuid, y uuid); #plan select * from myx where x in ('1aea00e5db6e0810b554fde31d961965') or y = '1aea00e5db6e0810b554fde31d961965'; % .plan # table_name _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list