summaryrefslogtreecommitdiff
path: root/mysql-test/r/having.result
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2017-11-02 15:56:18 -0700
committerIgor Babaev <igor@askmonty.org>2017-11-02 15:57:13 -0700
commitbeac522b550b0c8b9c7a4451bf1b851e83fd828f (patch)
treeee1babdd05b2c8ca93670b17e010d00d831e3da1 /mysql-test/r/having.result
parentb0cfb1686773c38955c254d29d196c1866e7e06a (diff)
downloadmariadb-git-beac522b550b0c8b9c7a4451bf1b851e83fd828f.tar.gz
Fixed mdev-14093 Wrong result upon JOIN with INDEX with no rows
in joined table + GROUP BY + GROUP_CONCAT + HAVING + ORDER BY [by field from HAVING] + 1 row expected The fix is actually a port of the fix for bug #17055185 from mysql code line (see commit f289aeeef0743508ff87211084453b3b88a6d017 by Mithun C Y into mysql-5.6). The test case for the bug #17055185 was also ported.
Diffstat (limited to 'mysql-test/r/having.result')
-rw-r--r--mysql-test/r/having.result73
1 files changed, 73 insertions, 0 deletions
diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result
index 18fb5e2de72..b3d0f281415 100644
--- a/mysql-test/r/having.result
+++ b/mysql-test/r/having.result
@@ -727,3 +727,76 @@ A COUNT(*)
DROP VIEW v1;
DROP TABLE t1;
End of 10.1 tests
+#
+# MDEV-14093: GROUP BY with HAVING over function + ORDER BY
+#
+CREATE TABLE _authors (
+id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT,
+name VARCHAR(100),
+some_field MEDIUMINT(8) UNSIGNED,
+PRIMARY KEY (id),
+index(some_field)
+);
+CREATE TABLE _books (
+id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT,
+title VARCHAR(100),
+PRIMARY KEY (id)
+);
+CREATE TABLE _books2authors (
+author_id MEDIUMINT(8) DEFAULT 0,
+book_id MEDIUMINT(8) DEFAULT 0,
+index(author_id),
+index(book_id)
+);
+INSERT INTO _authors (name, some_field) VALUES
+('author1', 1),('author2', 2),('author3', 3);
+INSERT INTO _books (title) VALUES
+('book1'),('book2'),('book3');
+INSERT INTO _books2authors (author_id, book_id) VALUES
+(2,1),(3,2),(3,3);
+SELECT A.id,
+GROUP_CONCAT(B.title ORDER BY B.title DESC SEPARATOR ',') AS books,
+some_field-1 AS having_field
+FROM _authors A
+LEFT JOIN _books2authors B2A FORCE INDEX(author_id)
+ON B2A.author_id = A.id
+LEFT JOIN
+_books B ON B.id = B2A.book_id
+GROUP BY A.id
+HAVING having_field < 1
+ORDER BY having_field ASC;
+id books having_field
+1 NULL 0
+DROP TABLE _authors, _books, _books2authors;
+#
+# Bug#17055185: WRONG RESULTS WHEN RUNNING A SELECT THAT INCLUDE
+# A HAVING BASED ON A FUNCTION.
+#
+CREATE TABLE series (
+val INT(10) UNSIGNED NOT NULL
+);
+INSERT INTO series VALUES(1);
+CREATE FUNCTION next_seq_value() RETURNS INT
+BEGIN
+DECLARE next_val INT;
+SELECT val INTO next_val FROM series;
+UPDATE series SET val=mod(val + 1, 2);
+RETURN next_val;
+END;
+|
+CREATE TABLE t1 (t INT, u INT, KEY(t));
+INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
+(16, 17), (17, 17);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t)
+GROUP BY t HAVING r = 1 ORDER BY t1.u;
+t r
+10 1
+12 1
+15 1
+17 1
+DROP TABLE t1;
+DROP FUNCTION next_seq_value;
+DROP TABLE series;