summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <kostja@oak.local>2003-08-06 16:58:03 +0400
committerunknown <kostja@oak.local>2003-08-06 16:58:03 +0400
commita8cb3628b7b37503fa02e9f3b091eff5a3c3c399 (patch)
tree97ce56c35330de689cc9dbeddc5acd8b494ad0c7
parentb97d0ea2c3c2d325c56f01a8edf26e7944dea749 (diff)
downloadmariadb-git-a8cb3628b7b37503fa02e9f3b091eff5a3c3c399.tar.gz
fix for bug #958 and tests for it
aligned with Sergey notes. sql/records.cc: fix for bug #958 - big select with count distinct and group by aligned with Sergey notes.
-rw-r--r--mysql-test/r/count_distinct3.result7
-rw-r--r--mysql-test/t/count_distinct3.test55
-rw-r--r--sql/records.cc8
3 files changed, 69 insertions, 1 deletions
diff --git a/mysql-test/r/count_distinct3.result b/mysql-test/r/count_distinct3.result
new file mode 100644
index 00000000000..633bb2fa252
--- /dev/null
+++ b/mysql-test/r/count_distinct3.result
@@ -0,0 +1,7 @@
+DROP TABLE IF EXISTS t1, t2;
+CREATE TABLE t1 (id INTEGER, grp TINYINT, id_rev INTEGER);
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+4181000
+SELECT COUNT(DISTINCT id) FROM t1 GROUP BY grp;
+DROP TABLE t1;
diff --git a/mysql-test/t/count_distinct3.test b/mysql-test/t/count_distinct3.test
new file mode 100644
index 00000000000..e6cc98d47df
--- /dev/null
+++ b/mysql-test/t/count_distinct3.test
@@ -0,0 +1,55 @@
+#
+# this is a test for error 1032 in count(distinct) + group by, introduced in
+# mysql-4.1
+#
+
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+
+CREATE TABLE t1 (id INTEGER, grp TINYINT, id_rev INTEGER);
+
+--disable_query_log
+SET @rnd_max= 2147483647;
+let $1 = 1000;
+while ($1)
+{
+ SET @rnd= RAND();
+ SET @id = CAST(@rnd * @rnd_max AS UNSIGNED);
+ SET @id_rev= @rnd_max - @id;
+ SET @grp= CAST(128.0 * @rnd AS UNSIGNED);
+ INSERT INTO t1 (id, grp, id_rev) VALUES (@id, @grp, @id_rev);
+ dec $1;
+}
+CREATE TABLE t2 SELECT * FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
+INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
+DROP TABLE t2;
+--enable_query_log
+
+SELECT COUNT(*) FROM t1;
+
+# As t1 contains random numbers, results are different from test to test.
+# That's okay, because we test only that select doesn't yield an
+# error. Note, that --disable_result_log doesn't suppress error output.
+
+--disable_result_log
+SELECT COUNT(DISTINCT id) FROM t1 GROUP BY grp;
+--enable_result_log
+DROP TABLE t1;
diff --git a/sql/records.cc b/sql/records.cc
index 783ca663dfe..72a6d480356 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -73,7 +73,13 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
info->ref_pos=table->file->ref;
table->file->rnd_init(0);
- if (! (specialflag & SPECIAL_SAFE_MODE) &&
+ /*
+ table->sort.addon_field is checked because if we use addon fields,
+ it doesn't make sense to use cache - we don't read from the table
+ and table->sort.io_cache is read sequentially
+ */
+ if (!table->sort.addon_field &&
+ ! (specialflag & SPECIAL_SAFE_MODE) &&
thd->variables.read_rnd_buff_size &&
!table->file->fast_key_read() &&
(table->db_stat & HA_READ_ONLY ||