Details
Description
CREATE OR REPLACE ALGORITHM = MERGE VIEW v AS SELECT 1 a, SLEEP(3) b, SLEEP(3) c FROM DUAL; EXPLAIN EXTENDED SELECT a FROM v;
EXPLAIN EXTENDED shows us what we want to see... but it's a lie
If you execute the SELECT, it will sleep for 6 seconds, because columns b and c are evaluated.
Note that the bug will NOT happen in this case:
\W CREATE OR REPLACE TABLE t (a INT) ENGINE = InnoDB; INSERT INTO t VALUES (1); CREATE OR REPLACE ALGORITHM = MERGE VIEW v AS SELECT a, SLEEP(3) b, SLEEP(3) c FROM t; EXPLAIN EXTENDED SELECT a FROM v;
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Correction: the problem is related to derived tables, not necessarily views. In fact, you can repeat it in this way:
The above query is weird, but the view example comes from a real case.