Wrong result with second execution of prepared statement with semijoin + view

Bug #849763 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
High
Sergey Petrunia

Bug Description

The following query:
SELECT * FROM t2 WHERE a = SOME (
   SELECT a FROM v1 WHERE v1.c = t2.c
);

returns a no rows on its second execution as a prepared statement with semijoin.

explain:

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; Start temporary
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 Using where; End temporary; Using join buffer (flat, BNL join)

correct result:

EXECUTE st1;
a b c
1 r r

minimal optimizer switch: semijoin=on;
full 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=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,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

bzr version-info
revision-id: <email address hidden>
date: 2011-09-10 18:01:27 +0300
build-date: 2011-09-14 10:54:25 +0300
revno: 3183
branch-nick: maria-5.3

test case:

--source include/have_innodb.inc
SET SESSION optimizer_switch='semijoin=on';

CREATE TABLE t1 ( c varchar(1)) engine=innodb;
INSERT INTO t1 VALUES ('r');

CREATE TABLE t2 ( a integer, b varchar(1), c varchar(1)) engine=innodb;
INSERT INTO t2 VALUES (1,'r','r');

CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;

PREPARE st1 FROM '
        SELECT * FROM t2 WHERE a = SOME (
                SELECT a FROM v1 WHERE v1.c = t2.c
        )
';
EXECUTE st1;
EXECUTE st1;

Changed in maria:
milestone: none → 5.3
assignee: nobody → Sergey Petrunia (sergefp)
Changed in maria:
importance: Undecided → High
Changed in maria:
status: New → 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.