Details
-
Type:
Bug
-
Status: Closed
-
Resolution: Not a Bug
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
Description
The following view:
CREATE VIEW v1 AS SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9 ;
is executed with an inferior plan after mwl#106 .
Before mwl106:
explain:
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9
2 DERIVED t1 range b,b_2 b 4 NULL 226 Using where; Using temporary
counters:
Handler_read_next 0
Handler_read_prev 8
Handler_read_rnd 0
Handler_read_rnd_next 19
Handler_write 20
after mwl106:
explain:
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 222
2 DERIVED t1 ref b,b_2 b_2 4 const 222 Using where; Using index; Using temporary; Using filesort
counters:
-Handler_read_next 208
-Handler_read_prev 0
-Handler_read_rnd 9
-Handler_read_rnd_next 219
-Handler_tmp_update 0
-Handler_tmp_write 217
-Handler_write 2
The results returned are also different, but I do not know if the difference is legitimate or not.
Test case:
CREATE TABLE t1 (
a INT,
b INT NOT NULL,
c char(100),
KEY (b, c),
KEY (b, a, c)
)
INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8), (9, 9, 9);
INSERT INTO t1 SELECT a + 10, b, c FROM t1;
INSERT INTO t1 SELECT a + 20, b, c FROM t1;
INSERT INTO t1 SELECT a + 40, b, c FROM t1;
INSERT INTO t1 SELECT a + 80, b, c FROM t1;
INSERT INTO t1 SELECT a + 160, b, c FROM t1;
INSERT INTO t1 SELECT a + 320, b, c FROM t1;
INSERT INTO t1 SELECT a + 640, b, c FROM t1;
INSERT INTO t1 SELECT a + 1280, b, c FROM t1 LIMIT 80;
CREATE VIEW v1 AS SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9 ;
EXPLAIN SELECT * FROM v1;
FLUSH STATUS;
SELECT * FROM v1;
SHOW STATUS LIKE '%Handler%';
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Re: Inferior plan selected after mwl#106 with ORDER BY
Here is another instance of the same problem. In the test case below, mwl106 causes the UDF to be executed twice per row. The counters report the use of Handler_tmp_write :
--source include/have_udf.inc
eval CREATE FUNCTION sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_SO";
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(0),(0),(0);
CREATE VIEW v1 AS SELECT sequence() AS seq FROM t1 ORDER BY seq ASC ;
FLUSH STATUS;
SELECT * FROM v1;
SHOW STATUS LIKE '%Handler_%';