Wrong result with merge view , derived table, first execution of a prepared statement

Bug #874035 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
High
Igor Babaev

Bug Description

The following query:

        SELECT * FROM (
                SELECT *
                FROM t2
                LEFT JOIN v1
                ON (t2.a = v1.b)
        ) AS derived

returns the following incorrect result when run the first time as a prepared statement:

a b
6 0

The second run, as well as non-prepared execution, return the correct result:

a b
6 NULL

explain:

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
2 DERIVED t2 system NULL NULL NULL NULL 1
2 DERIVED t1 ALL NULL NULL NULL NULL 0 Using where

optimizer switch:

index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

repeatable on maria-5.3. Not repeatable on maria-5.2, mysql-5.5

bzr version-info:

revision-id: <email address hidden>
date: 2011-10-13 13:44:50 +0200
build-date: 2011-10-14 13:08:11 +0300
revno: 3233
branch-nick: maria-5.3

test case:

CREATE TABLE t2 (a int NOT NULL);
INSERT INTO t2 VALUES (6);

CREATE TABLE t1 (b int NOT NULL);
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;

PREPARE st1 FROM '
        SELECT * FROM (
                SELECT *
                FROM t2
                LEFT JOIN v1
                ON (t2.a = v1.b)
        ) AS derived
';

EXECUTE st1;
EXECUTE st1;

Changed in maria:
milestone: none → 5.3
assignee: nobody → Igor Babaev (igorb-seattle)
Changed in maria:
status: New → Confirmed
importance: Undecided → High
Changed in maria:
status: Confirmed → In Progress
Changed in maria:
status: In Progress → Fix Committed
Changed in maria:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.