summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-12-10 17:51:07 +0200
committerunknown <monty@hundin.mysql.fi>2001-12-10 17:51:07 +0200
commit2d1e16eb04a3e78830447400a55f7cd2291e566c (patch)
tree40df440fc1708f1f09301e5f4f923c08a4470ec9
parent6f8f45e9592aa7f2ca48168d51e1624cce158797 (diff)
downloadmariadb-git-2d1e16eb04a3e78830447400a55f7cd2291e566c.tar.gz
Fixed bug in GROUP BY ... DESC
Docs/manual.texi: Changelog libmysql/libmysql.c: Fixed bug with mysql_use_result() when mysql_query() is called before mysql_free_result(). mysql-test/r/group_by.result: New tests mysql-test/t/group_by.test: New tests sql/stacktrace.c: Fix for SCO
-rw-r--r--Docs/manual.texi2
-rw-r--r--libmysql/libmysql.c2
-rw-r--r--mysql-test/r/group_by.result30
-rw-r--r--mysql-test/t/group_by.test25
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_yacc.yy19
-rw-r--r--sql/stacktrace.c2
7 files changed, 68 insertions, 14 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index a82b0a83cb5..416e16ff710 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -46839,6 +46839,8 @@ not yet 100% confident in this code.
@appendixsubsec Changes in release 3.23.47
@itemize @bullet
@item
+Fixed that @code{GROUP BY expr DESC} works.
+@item
Fixed bug when using @code{t1 LEFT JOIN t2 ON t2.key=constant}.
@item
@code{mysqlconfig} now also work with binary (relocated) distributions.
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 4a5e534389e..8a73f694e41 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1955,6 +1955,8 @@ mysql_fetch_row(MYSQL_RES *res)
DBUG_PRINT("info",("end of data"));
res->eof=1;
res->handle->status=MYSQL_STATUS_READY;
+ /* Don't clear handle in mysql_free_results */
+ res->handle=0;
}
}
DBUG_RETURN((MYSQL_ROW) NULL);
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index 2c4a5cecbb1..d5fcc7d85e8 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -34,3 +34,33 @@ Test Procedures 0
2 a 0
1+1 a count(*)
2 a 0
+table type possible_keys key key_len ref rows Extra
+t1 ALL NULL NULL NULL NULL 6 Using temporary
+userid count(*)
+3 3
+2 1
+1 2
+table type possible_keys key key_len ref rows Extra
+t1 range spID spID 5 NULL 2 where used; Using index; Using temporary
+table type possible_keys key key_len ref rows Extra
+t1 range spID spID 5 NULL 2 where used; Using index
+spid count(*)
+1 1
+2 2
+spid count(*)
+2 2
+1 1
+table type possible_keys key key_len ref rows Extra
+t1 ALL NULL NULL NULL NULL 6 Using filesort
+spid sum(userid)
+5 3
+4 3
+3 3
+2 3
+1 1
+table type possible_keys key key_len ref rows Extra
+t1 index NULL score 3 NULL 6 Using index
+score count(*)
+3 3
+2 1
+1 2
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index e75841dc6d0..efa1744feee 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -38,7 +38,6 @@ INSERT INTO t2 VALUES (3,'name','pass','mail','Y','v','n','adr','1','1','1');
SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID GROUP BY t2.userid;
SELECT t2.userid, MIN(t1.score) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid;
SELECT t2.userid, MIN(t1.score+0.0) FROM t1, t2 WHERE t1.userID=t2.userID AND t1.spID=2 GROUP BY t2.userid;
-
drop table test.t1,test.t2;
#
@@ -220,3 +219,27 @@ select 1+1, "a",count(*) from t1 where foo in (2);
insert into t1 values (1);
select 1+1,"a",count(*) from t1 where foo in (2);
drop table t1;
+
+#
+# Test GROUP BY DESC
+
+CREATE TABLE t1 (
+ spID int(10) unsigned,
+ userID int(10) unsigned,
+ score smallint(5) unsigned,
+ key (spid),
+ key (score)
+);
+
+INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3);
+explain select userid,count(*) from t1 group by userid desc;
+select userid,count(*) from t1 group by userid desc;
+explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc;
+explain select spid,count(*) from t1 where spid between 1 and 2 group by spid;
+select spid,count(*) from t1 where spid between 1 and 2 group by spid;
+select spid,count(*) from t1 where spid between 1 and 2 group by spid desc;
+explain select sql_big_result spid,sum(userid) from t1 group by spid desc;
+select sql_big_result spid,sum(userid) from t1 group by spid desc;
+explain select sql_big_result score,count(*) from t1 group by score desc;
+select sql_big_result score,count(*) from t1 group by score desc;
+drop table t1;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 7a4a5034b18..8f81af3b548 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -140,7 +140,7 @@ typedef struct st_lex {
enum lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
- uint in_sum_expr,grant,grant_tot_col,which_columns, sort_default;
+ uint in_sum_expr,grant,grant_tot_col,which_columns;
thr_lock_type lock_option;
bool create_refs,drop_primary,drop_if_exists,local_file;
bool in_comment,ignore_space,verbose;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 5a1c6baf1e4..c1935df732f 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -470,7 +470,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
ULONGLONG_NUM
%type <item>
- literal text_literal insert_ident group_ident order_ident
+ literal text_literal insert_ident order_ident
simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
using_list
@@ -1869,10 +1869,10 @@ group_clause:
| GROUP BY group_list
group_list:
- group_list ',' group_ident
- { if (add_group_to_list($3,(bool) 1)) YYABORT; }
- | group_ident
- { if (add_group_to_list($1,(bool) 1)) YYABORT; }
+ group_list ',' order_ident order_dir
+ { if (add_group_to_list($3,(bool) $4)) YYABORT; }
+ | order_ident order_dir
+ { if (add_group_to_list($1,(bool) $2)) YYABORT; }
/*
** Order by statement in select
@@ -1883,7 +1883,7 @@ opt_order_clause:
| order_clause
order_clause:
- ORDER_SYM BY { Lex->sort_default=1; } order_list
+ ORDER_SYM BY order_list
order_list:
order_list ',' order_ident order_dir
@@ -1893,8 +1893,8 @@ order_list:
order_dir:
/* empty */ { $$ = 1; }
- | ASC { $$ = Lex->sort_default=1; }
- | DESC { $$ = Lex->sort_default=0; }
+ | ASC { $$ =1; }
+ | DESC { $$ =0; }
limit_clause:
@@ -2452,9 +2452,6 @@ table_wild:
| ident '.' ident '.' '*'
{ $$ = new Item_field((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS : $1.str),$3.str,"*"); }
-group_ident:
- order_ident order_dir
-
order_ident:
expr { $$=$1; }
diff --git a/sql/stacktrace.c b/sql/stacktrace.c
index fba9927f5dd..f4415571f1b 100644
--- a/sql/stacktrace.c
+++ b/sql/stacktrace.c
@@ -218,7 +218,7 @@ void write_core(int sig)
{
signal(sig, SIG_DFL);
pthread_kill(pthread_self(), sig);
-#if defined(P_MYID)
+#if defined(P_MYID) && !defined(SCO)
/* On Solaris, the above kill is not enough */
sigsend(P_PID,P_MYID,sig);
#endif