1
/* Copyright (C) 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef TABLE_MAPPING_H
17
#define TABLE_MAPPING_H
19
/* Forward declarations */
26
The table mapping is used to map table id's to table pointers
29
RELAY_LOG For mapping table id:s to tables when receiving events.
34
in the table_mapping class, the memory is allocated and never freed (until
35
destruction). So this is a good candidate for allocating inside a MEM_ROOT:
36
it gives the efficient allocation in chunks (like in expand()). So I have
37
introduced a MEM_ROOT.
39
Note that inheriting from Sql_alloc had no effect: it has effects only when
40
"ptr= new table_mapping" is called, and this is never called. And it would
41
then allocate from thd->mem_root which is a highly volatile object (reset
42
from example after executing each query, see dispatch_command(), it has a
43
free_root() at end); as the table_mapping object is supposed to live longer
44
than a query, it was dangerous.
45
A dedicated MEM_ROOT needs to be used, see below.
64
Table* get_table(ulong table_id);
66
int set_table(ulong table_id, Table* table);
67
int remove_table(ulong table_id);
69
ulong count() const { return m_table_ids.records; }
73
This is a POD (Plain Old Data). Keep it that way (we apply offsetof() to
74
it, which only works for PODs)
84
entry *find_entry(ulong table_id)
86
return (entry *)hash_search(&m_table_ids,
93
Head of the list of free entries; "free" in the sense that it's an
94
allocated entry free for use, NOT in the sense that it's freed
99
/* Correspondance between an id (a number) and a Table object */