Re: what can a sequence of handler::index_XXX be interrupted by?

Sergey Petrunya <[email protected]>
Newsgroups gmane.comp.db.mysql.devel
Message-ID <20110728074637.GB30266@pslp2>
On Wed, Jul 27, 2011 at 10:44:22PM -0400, Zardosht Kasheff wrote:
> Actually, let me put the question another way.
> 
> Given that we have had one call of handler::index_init with some thd
> and keynr, are we guaranteed to NOT get another call to
> handler::index_init with the SAME thd and keynr, until we get a call
> to handler::index_end for the first call?

No. It's easiest to show with a counterexample:

create table parent (a int, b int);
insert into parent values (1,1),(2,2); 
create table child1(a int, key(a));
create table child2(b int, key(b));
insert into child1 select a from parent;
insert into child1 select b from parent;

MariaDB [test]> explain select * from parent P, child1 C1, child2 C2 where P.a=C1.a and P.b=C2.b;
+----+-------------+-------+------+---------------+------+---------+----------+------+--------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref      | rows | Extra                    |
+----+-------------+-------+------+---------------+------+---------+----------+------+--------------------------+
|  1 | SIMPLE      | P     | ALL  | NULL          | NULL | NULL    | NULL     | 2 |                          |
|  1 | SIMPLE      | C1    | ref  | a             | a    | 5       | test.P.a | 1 | Using where; Using index |
|  1 | SIMPLE      | C2    | ref  | b             | b    | 5       | test.P.b | 1 | Using where; Using index |
+----+-------------+-------+------+---------------+------+---------+----------+------+--------------------------+
3 rows in set (0.01 sec)

(gdb) b ha_myisam::index_init
  Breakpoint 1 at 0x83eb12e: file ../../../sql/handler.h, line 2013.
(gdb) b ha_myisam::index_end
  Breakpoint 2 at 0x83eb139: file ../../../sql/handler.h, line 2014.

MariaDB [test]> select * from parent P, child1 C1, child2 C2 where P.a=C1.a and P.b=C2.b;

  Breakpoint 1, handler::index_init (this=0xafdd9f0, idx=0, sorted=false) at ../../../sql/handler.h:2013
(gdb) c
  Continuing.

  Breakpoint 1, handler::index_init (this=0xafe1568, idx=0, sorted=false) at ../../../sql/handler.h:2013
(gdb) c
  Continuing.
  
  Breakpoint 2, handler::index_end (this=0xafdd9f0) at ../../../sql/handler.h:2014
(gdb) c
  Continuing.
  
  Breakpoint 2, handler::index_end (this=0xafe1568) at ../../../sql/handler.h:2014
(gdb) c
  Continuing.

Breakpoint hits with this=0xafdd9f0 are for table C1, and those with this=0xafe1568 are for table C2

BR
 Sergey
-- 
Sergey Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog

-- 
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.