21
21
the most natural (easiest, fastest) way to do it is to
22
22
compute List<Item> field_list not in mysql_ha_read
23
but in mysql_ha_open, and then store it in TABLE structure.
23
but in mysql_ha_open, and then store it in Table structure.
25
25
The problem here is that mysql_parse calls free_item to free all the
26
26
items allocated at the end of every query. The workaround would to
36
36
There are two containers holding information about open handler tables.
37
The first is 'thd->handler_tables'. It is a linked list of TABLE objects.
37
The first is 'thd->handler_tables'. It is a linked list of Table objects.
38
38
It is used like 'thd->open_tables' in the table cache. The trick is to
39
39
exchange these two lists during open and lock of tables. Thus the normal
40
40
table cache code can be used.
41
41
The second container is a HASH. It holds objects of the type TABLE_LIST.
42
42
Despite its name, no lists of tables but only single structs are hashed
43
43
(the 'next' pointer is always NULL). The reason for theis second container
44
is, that we want handler tables to survive FLUSH TABLE commands. A table
45
affected by FLUSH TABLE must be closed so that other threads are not
44
is, that we want handler tables to survive FLUSH Table commands. A table
45
affected by FLUSH Table must be closed so that other threads are not
46
46
blocked by handler tables still in use. Since we use the normal table cache
47
47
functions with 'thd->handler_tables', the closed tables are removed from
48
48
this list. Hence we need the original open information for the handler
49
49
table in the case that it is used again. This information is handed over
50
50
to mysql_ha_open() as a TABLE_LIST. So we store this information in the
51
second container, where it is not affected by FLUSH TABLE. The second
51
second container, where it is not affected by FLUSH Table. The second
52
52
container is implemented as a hash for performance reasons. Consequently,
53
53
we use it not only for re-opening a handler table, but also for the
54
54
HANDLER ... READ commands. For this purpose, we store a pointer to the
55
TABLE structure (in the first container) in the TBALE_LIST object in the
55
Table structure (in the first container) in the TBALE_LIST object in the
56
56
second container. When the table is flushed, the pointer is cleared.
105
105
else if (tables->table)
107
107
/* Must be a temporary table */
108
TABLE *table= tables->table;
108
Table *table= tables->table;
109
109
table->file->ha_index_or_rnd_end();
110
110
table->query_id= thd->query_id;
111
111
table->open_by_handler= 0;