1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

cleanup: (*order->item) -> item

and minor style fixes
This commit is contained in:
Sergei Golubchik
2022-04-28 16:59:50 +02:00
parent 7215b00354
commit bc9102eb81
7 changed files with 44 additions and 42 deletions

View File

@ -1,4 +1,3 @@
drop table if exists t1,t2,t3;
create table t1 (a int); create table t1 (a int);
select count(a) as b from t1 where a=0 having b > 0; select count(a) as b from t1 where a=0 having b > 0;
b b
@ -880,8 +879,10 @@ h
# #
# #
drop table t1; drop table t1;
#
# End of 10.3 tests # End of 10.3 tests
# #
#
# MDEV-18681: AND formula in HAVING with several occurances # MDEV-18681: AND formula in HAVING with several occurances
# of the same field f in different conjuncts + f=constant # of the same field f in different conjuncts + f=constant
# #
@ -906,4 +907,6 @@ INSERT INTO t VALUES ('a'),('b');
SELECT * FROM t HAVING f = 'foo'; SELECT * FROM t HAVING f = 'foo';
f f
DROP TABLE t; DROP TABLE t;
#
# End of 10.4 tests # End of 10.4 tests
#

View File

@ -1,10 +1,6 @@
# test of problems with having (Reported by Mark Rogers) # test of problems with having (Reported by Mark Rogers)
# #
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
create table t1 (a int); create table t1 (a int);
select count(a) as b from t1 where a=0 having b > 0; select count(a) as b from t1 where a=0 having b > 0;
insert into t1 values (null); insert into t1 values (null);
@ -207,7 +203,7 @@ select count(*) from t1 group by col1 having col1 = 10;
select count(*) as count_col1 from t1 group by col1 having col1 = 10; select count(*) as count_col1 from t1 group by col1 having col1 = 10;
select count(*) as count_col1 from t1 as tmp1 group by col1 having col1 = 10; select count(*) as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
select count(*) from t1 group by col2 having col2 = 'hello'; select count(*) from t1 group by col2 having col2 = 'hello';
--error 1054 --error ER_BAD_FIELD_ERROR
select count(*) from t1 group by col2 having col1 = 10; select count(*) from t1 group by col2 having col1 = 10;
select col1 as count_col1 from t1 as tmp1 group by col1 having col1 = 10; select col1 as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
select col1 as count_col1 from t1 as tmp1 group by col1 having count_col1 = 10; select col1 as count_col1 from t1 as tmp1 group by col1 having count_col1 = 10;
@ -221,10 +217,10 @@ select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col1 =
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having count_col1 = 10; select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having count_col1 = 10;
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col2 = 'hello'; select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col2 = 'hello';
select col1 as count_col1,col2 as group_col2 from t1 as tmp1 group by col1,col2 having group_col2 = 'hello'; select col1 as count_col1,col2 as group_col2 from t1 as tmp1 group by col1,col2 having group_col2 = 'hello';
--error 1064 --error ER_PARSE_ERROR
select sum(col1) as co12 from t1 group by col2 having col2 10; select sum(col1) as co12 from t1 group by col2 having col2 10;
select sum(col1) as co2, count(col2) as cc from t1 group by col1 having col1 =10; select sum(col1) as co2, count(col2) as cc from t1 group by col1 having col1 =10;
--error 1054 --error ER_BAD_FIELD_ERROR
select t2.col2 from t2 group by t2.col1, t2.col2 having t1.col1 <= 10; select t2.col2 from t2 group by t2.col1, t2.col2 having t1.col1 <= 10;
@ -273,7 +269,7 @@ having (select col_t1 from t2 where col_t1 = col_t2 order by col_t2 limit 1);
# nested queries with HAVING, inner having column resolved in outer FROM clause # nested queries with HAVING, inner having column resolved in outer FROM clause
# the outer having column is not referenced in GROUP BY which results in an error # the outer having column is not referenced in GROUP BY which results in an error
--error 1054 --error ER_BAD_FIELD_ERROR
select t1.col1 from t1 select t1.col1 from t1
where t1.col2 in where t1.col2 in
(select t2.col2 from t2 (select t2.col2 from t2
@ -302,7 +298,7 @@ having col_t1 > 10 and
# correlated subqueries - inner having column 't1.col2' resolves to # correlated subqueries - inner having column 't1.col2' resolves to
# the outer FROM clause, which cannot be used because the outer query # the outer FROM clause, which cannot be used because the outer query
# is grouped # is grouped
--error 1054 --error ER_BAD_FIELD_ERROR
select sum(col1) from t1 select sum(col1) from t1
group by col_t1 group by col_t1
having col_t1 in (select sum(t2.col1) from t2 having col_t1 in (select sum(t2.col1) from t2
@ -318,11 +314,11 @@ having col_t1 in (select sum(t2.col1) from t2
# #
# queries with joins and ambiguous column names # queries with joins and ambiguous column names
# #
--error 1052 --error ER_NON_UNIQ_ERROR
select t1.col1, t2.col1 from t1, t2 where t1.col1 = t2.col1 select t1.col1, t2.col1 from t1, t2 where t1.col1 = t2.col1
group by t1.col1, t2.col1 having col1 = 2; group by t1.col1, t2.col1 having col1 = 2;
--error 1052 --error ER_NON_UNIQ_ERROR
select t1.col1*10+t2.col1 from t1,t2 where t1.col1=t2.col1 select t1.col1*10+t2.col1 from t1,t2 where t1.col1=t2.col1
group by t1.col1, t2.col1 having col1 = 2; group by t1.col1, t2.col1 having col1 = 2;
@ -352,7 +348,7 @@ select count(s1) from t1 group by s1 having count(1+1)=2;
select count(s1) from t1 group by s1 having s1*0=0; select count(s1) from t1 group by s1 having s1*0=0;
-- error 1052 -- error ER_NON_UNIQ_ERROR
select * from t1 a, t1 b group by a.s1 having s1 is null; select * from t1 a, t1 b group by a.s1 having s1 is null;
# ANSI requires: 0 rows # ANSI requires: 0 rows
# MySQL returns: # MySQL returns:
@ -912,7 +908,9 @@ alter table t1 add column b int default (rand()+1+3);
select default(b) AS h FROM t1 HAVING h > "2"; select default(b) AS h FROM t1 HAVING h > "2";
drop table t1; drop table t1;
--echo #
--echo # End of 10.3 tests --echo # End of 10.3 tests
--echo #
--echo # --echo #
--echo # MDEV-18681: AND formula in HAVING with several occurances --echo # MDEV-18681: AND formula in HAVING with several occurances
@ -930,7 +928,6 @@ HAVING t.f != 112 AND t.f = 'x' AND t.f != 'a';
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo # --echo #
--echo # MDEV-20200: AddressSanitizer: use-after-poison in --echo # MDEV-20200: AddressSanitizer: use-after-poison in
--echo # Item_direct_view_ref::get_null_ref_table --echo # Item_direct_view_ref::get_null_ref_table
@ -943,4 +940,6 @@ SELECT * FROM t HAVING f = 'foo';
# Cleanup # Cleanup
DROP TABLE t; DROP TABLE t;
--echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo #

View File

@ -1,6 +1,5 @@
set @subselect_innodb_tmp=@@optimizer_switch; set @subselect_innodb_tmp=@@optimizer_switch;
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
drop table if exists t1,t2,t3;
CREATE TABLE t1 CREATE TABLE t1
( (
FOLDERID VARCHAR(32)BINARY NOT NULL FOLDERID VARCHAR(32)BINARY NOT NULL
@ -154,6 +153,9 @@ EXECUTE my_stmt;
b count(*) b count(*)
deallocate prepare my_stmt; deallocate prepare my_stmt;
drop table t1,t2; drop table t1,t2;
#
# End of 4.1 tests
#
CREATE TABLE t1 ( CREATE TABLE t1 (
school_name varchar(45) NOT NULL, school_name varchar(45) NOT NULL,
country varchar(45) NOT NULL, country varchar(45) NOT NULL,
@ -287,7 +289,6 @@ LIMIT 10;
col_time_key col_datetime_key col_time_key col_datetime_key
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
# End of Bug #58756
# #
# Bug#60085 crash in Item::save_in_field() with time data type # Bug#60085 crash in Item::save_in_field() with time data type
# #
@ -356,7 +357,9 @@ LIMIT 1;
maxkey maxkey
NULL NULL
DROP TABLE t1,t2; DROP TABLE t1,t2;
End of 5.1 tests #
# End of 5.1 tests
#
# #
# lp:827416 Crash in select_describe() on EXPLAIN with DISTINCT in nested subqueries # lp:827416 Crash in select_describe() on EXPLAIN with DISTINCT in nested subqueries
# #
@ -663,4 +666,6 @@ a b
execute stmt; execute stmt;
a b a b
drop table t1,t2; drop table t1,t2;
#
# End of 10.4 tests # End of 10.4 tests
#

View File

@ -4,9 +4,6 @@
# settings are not relevant. # settings are not relevant.
set @subselect_innodb_tmp=@@optimizer_switch; set @subselect_innodb_tmp=@@optimizer_switch;
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
# #
# key field overflow test # key field overflow test
@ -164,7 +161,9 @@ EXECUTE my_stmt;
deallocate prepare my_stmt; deallocate prepare my_stmt;
drop table t1,t2; drop table t1,t2;
# End of 4.1 tests --echo #
--echo # End of 4.1 tests
--echo #
CREATE TABLE t1 ( CREATE TABLE t1 (
school_name varchar(45) NOT NULL, school_name varchar(45) NOT NULL,
@ -289,8 +288,6 @@ LIMIT 10;
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
--echo # End of Bug #58756
--echo # --echo #
--echo # Bug#60085 crash in Item::save_in_field() with time data type --echo # Bug#60085 crash in Item::save_in_field() with time data type
--echo # --echo #
@ -354,7 +351,9 @@ eval $query;
DROP TABLE t1,t2; DROP TABLE t1,t2;
--echo End of 5.1 tests --echo #
--echo # End of 5.1 tests
--echo #
--echo # --echo #
--echo # lp:827416 Crash in select_describe() on EXPLAIN with DISTINCT in nested subqueries --echo # lp:827416 Crash in select_describe() on EXPLAIN with DISTINCT in nested subqueries
@ -507,8 +506,6 @@ drop table t1,t2;
--echo # for a subquery from the expression used in ref access --echo # for a subquery from the expression used in ref access
--echo # --echo #
--source include/have_innodb.inc
CREATE TABLE t1 (i1 INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (i1 INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2); INSERT INTO t1 VALUES (1),(2);
@ -661,4 +658,6 @@ execute stmt;
drop table t1,t2; drop table t1,t2;
--echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo #

View File

@ -7874,8 +7874,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
else if (!ref || ref == not_found_item) else if (!ref || ref == not_found_item)
{ {
DBUG_ASSERT(reference_trough_name != 0); DBUG_ASSERT(reference_trough_name != 0);
if (!(ref= resolve_ref_in_select_and_group(thd, this, if (!(ref= resolve_ref_in_select_and_group(thd, this, context->select_lex)))
context->select_lex)))
goto error; /* Some error occurred (e.g. ambiguous names). */ goto error; /* Some error occurred (e.g. ambiguous names). */
if (ref == not_found_item) /* This reference was not resolved. */ if (ref == not_found_item) /* This reference was not resolved. */
@ -7888,8 +7887,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
if (unlikely(!outer_context)) if (unlikely(!outer_context))
{ {
/* The current reference cannot be resolved in this query. */ /* The current reference cannot be resolved in this query. */
my_error(ER_BAD_FIELD_ERROR,MYF(0), my_error(ER_BAD_FIELD_ERROR,MYF(0), full_name(), thd->where);
this->full_name(), thd->where);
goto error; goto error;
} }

View File

@ -8453,7 +8453,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, List<TABLE_LIST> &leaves,
select_lex->where= *conds; select_lex->where= *conds;
} }
thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup; thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
DBUG_RETURN(MY_TEST(thd->is_error())); DBUG_RETURN(thd->is_error());
err_no_arena: err_no_arena:
select_lex->is_item_list_lookup= save_is_item_list_lookup; select_lex->is_item_list_lookup= save_is_item_list_lookup;

View File

@ -24528,8 +24528,8 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields, if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
all_fields, false, true, from_window_spec)) all_fields, false, true, from_window_spec))
return 1; return 1;
if ((*order->item)->with_window_func && Item * const item= *order->item;
context_analysis_place != IN_ORDER_BY) if (item->with_window_func && context_analysis_place != IN_ORDER_BY)
{ {
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0)); my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1; return 1;
@ -24540,20 +24540,18 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
an ORDER BY clause an ORDER BY clause
*/ */
if (for_union && if (for_union && (item->with_sum_func() || item->with_window_func))
((*order->item)->with_sum_func() ||
(*order->item)->with_window_func))
{ {
my_error(ER_AGGREGATE_ORDER_FOR_UNION, MYF(0), number); my_error(ER_AGGREGATE_ORDER_FOR_UNION, MYF(0), number);
return 1; return 1;
} }
if (!(*order->item)->with_sum_func()) if (from_window_spec && item->with_sum_func() &&
continue; item->type() != Item::SUM_FUNC_ITEM)
{
if (from_window_spec && (*order->item)->type() != Item::SUM_FUNC_ITEM) item->split_sum_func(thd, ref_pointer_array,
(*order->item)->split_sum_func(thd, ref_pointer_array, all_fields, SPLIT_SUM_SELECT);
all_fields, SPLIT_SUM_SELECT); }
} }
return 0; return 0;
} }