17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
22
#ifndef DRIZZLED_SESSION_H
21
23
#define DRIZZLED_SESSION_H
25
#include "drizzled/plugin.h"
26
#include "drizzled/sql_locale.h"
27
#include "drizzled/resource_context.h"
28
#include "drizzled/cursor.h"
29
#include "drizzled/current_session.h"
30
#include "drizzled/sql_error.h"
31
#include "drizzled/file_exchange.h"
32
#include "drizzled/select_result_interceptor.h"
33
#include "drizzled/statistics_variables.h"
34
#include "drizzled/xid.h"
35
#include "drizzled/query_id.h"
36
#include "drizzled/named_savepoint.h"
37
#include "drizzled/transaction_context.h"
38
#include "drizzled/util/storable.h"
39
#include "drizzled/my_hash.h"
40
#include "drizzled/pthread_globals.h"
43
#include <sys/resource.h>
23
45
#include <algorithm>
25
#include <boost/make_shared.hpp>
26
#include <boost/thread/condition_variable.hpp>
51
#include "drizzled/identifier.h"
52
#include "drizzled/open_tables_state.h"
53
#include "drizzled/internal_error_handler.h"
54
#include "drizzled/diagnostics_area.h"
55
#include "drizzled/plugin/authorization.h"
57
#include "drizzled/catalog/instance.h"
58
#include "drizzled/catalog/local.h"
60
#include <boost/unordered_map.hpp>
62
#include <boost/thread/thread.hpp>
27
63
#include <boost/thread/mutex.hpp>
28
64
#include <boost/thread/shared_mutex.hpp>
29
#include <boost/thread/thread.hpp>
33
#include <sys/resource.h>
65
#include <boost/thread/condition_variable.hpp>
66
#include <boost/make_shared.hpp>
36
#include <drizzled/catalog/instance.h>
37
#include <drizzled/catalog/local.h>
38
#include <drizzled/copy_info.h>
39
#include <drizzled/cursor.h>
40
#include <drizzled/diagnostics_area.h>
41
#include <drizzled/file_exchange.h>
42
#include <drizzled/ha_data.h>
43
#include <drizzled/identifier.h>
44
#include <drizzled/lex_column.h>
45
#include <drizzled/my_hash.h>
46
#include <drizzled/named_savepoint.h>
47
#include <drizzled/open_tables_state.h>
48
#include <drizzled/plugin.h>
49
#include <drizzled/plugin/authorization.h>
50
#include <drizzled/pthread_globals.h>
51
#include <drizzled/query_id.h>
52
#include <drizzled/resource_context.h>
53
#include <drizzled/session/property_map.h>
54
#include <drizzled/session/state.h>
55
#include <drizzled/session/table_messages.h>
56
#include <drizzled/session/transactions.h>
57
#include <drizzled/sql_error.h>
58
#include <drizzled/sql_lex.h>
59
#include <drizzled/sql_locale.h>
60
#include <drizzled/statistics_variables.h>
61
#include <drizzled/system_variables.h>
62
#include <drizzled/system_variables.h>
63
#include <drizzled/table_ident.h>
64
#include <drizzled/transaction_context.h>
65
#include <drizzled/util/storable.h>
66
#include <drizzled/var.h>
67
#include <drizzled/visibility.h>
68
#include "drizzled/visibility.h"
69
70
#define MIN_HANDSHAKE_SIZE 6
106
111
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
107
112
extern uint32_t tc_heuristic_recover;
116
Local storage for proto that are tmp table. This should be enlarged
117
to hande the entire table-share for a local table. Once Hash is done,
118
we should consider exchanging the map for it.
120
typedef std::map <std::string, message::Table> ProtoCache;
123
The COPY_INFO structure is used by INSERT/REPLACE code.
124
The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
126
If a row is inserted then the copied variable is incremented.
127
If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
128
new data differs from the old one then the copied and the updated
129
variables are incremented.
130
The touched variable is incremented if a row was touched by the update part
131
of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
132
was actually changed or not.
137
ha_rows records; /**< Number of processed records */
138
ha_rows deleted; /**< Number of deleted records */
139
ha_rows updated; /**< Number of updated records */
140
ha_rows copied; /**< Number of copied records */
142
ha_rows touched; /* Number of touched records */
143
enum enum_duplicates handle_duplicates;
144
int escape_char, last_errno;
146
/* for INSERT ... UPDATE */
147
List<Item> *update_fields;
148
List<Item> *update_values;
149
/* for VIEW ... WITH CHECK OPTION */
167
} /* namespace drizzled */
169
/** @TODO why is this in the middle of the file */
170
#include <drizzled/lex_column.h>
109
178
#define Session_SENTRY_MAGIC 0xfeedd1ff
110
179
#define Session_SENTRY_GONE 0xdeadbeef
181
struct drizzle_system_variables
183
drizzle_system_variables()
186
How dynamically allocated system variables are handled:
188
The global_system_variables and max_system_variables are "authoritative"
189
They both should have the same 'version' and 'size'.
190
When attempting to access a dynamic variable, if the session version
191
is out of date, then the session version is updated and realloced if
192
neccessary and bytes copied from global to make up for missing data.
194
ulong dynamic_variables_version;
195
char * dynamic_variables_ptr;
196
uint32_t dynamic_variables_head; /* largest valid variable offset */
197
uint32_t dynamic_variables_size; /* how many bytes are in use */
199
uint64_t myisam_max_extra_sort_file_size;
200
uint64_t max_heap_table_size;
201
uint64_t tmp_table_size;
202
ha_rows select_limit;
203
ha_rows max_join_size;
204
uint64_t auto_increment_increment;
205
uint64_t auto_increment_offset;
206
uint64_t bulk_insert_buff_size;
207
uint64_t join_buff_size;
208
uint32_t max_allowed_packet;
209
uint64_t max_error_count;
210
uint64_t max_length_for_sort_data;
211
size_t max_sort_length;
212
uint64_t min_examined_row_limit;
213
bool optimizer_prune_level;
216
uint32_t optimizer_search_depth;
217
uint32_t div_precincrement;
218
uint64_t preload_buff_size;
219
uint32_t read_buff_size;
220
uint32_t read_rnd_buff_size;
221
bool replicate_query;
222
size_t sortbuff_size;
223
uint32_t thread_handling;
224
uint32_t tx_isolation;
225
size_t transaction_message_threshold;
226
uint32_t completion_type;
227
/* Determines which non-standard SQL behaviour should be enabled */
229
uint64_t max_seeks_for_key;
230
size_t range_alloc_block_size;
231
uint32_t query_alloc_block_size;
232
uint32_t query_prealloc_size;
233
uint64_t group_concat_max_len;
234
uint64_t pseudo_thread_id;
236
plugin::StorageEngine *storage_engine;
238
/* Only charset part of these variables is sensible */
239
const CHARSET_INFO *character_set_filesystem;
241
/* Both charset and collation parts of these variables are important */
242
const CHARSET_INFO *collation_server;
244
inline const CHARSET_INFO *getCollation(void)
246
return collation_server;
250
MY_LOCALE *lc_time_names;
252
Time_zone *time_zone;
112
255
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
257
} /* namespace drizzled */
259
#include "drizzled/sql_lex.h"
264
DRIZZLED_API void mark_transaction_to_rollback(Session *session, bool all);
267
Storage engine specific thread local data.
272
Storage engine specific thread local data.
273
Lifetime: one user connection.
277
* Resource contexts for both the "statement" and "normal"
280
* Resource context at index 0:
282
* Life time: one statement within a transaction. If @@autocommit is
283
* on, also represents the entire transaction.
285
* Resource context at index 1:
287
* Life time: one transaction within a connection.
291
* If the storage engine does not participate in a transaction,
292
* there will not be a resource context.
294
drizzled::ResourceContext resource_context[2];
296
Ha_data() :ha_ptr(NULL) {}
115
300
* Represents a client connection to the database server.
517
752
ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
518
753
size_t index= 0);
520
session::Transactions transaction;
756
* Structure used to manage "statement transactions" and
757
* "normal transactions". In autocommit mode, the normal transaction is
758
* equivalent to the statement transaction.
760
* Storage engines will be registered here when they participate in
761
* a transaction. No engine is registered more than once.
763
struct st_transactions {
764
std::deque<NamedSavepoint> savepoints;
767
* The normal transaction (since BEGIN WORK).
769
* Contains a list of all engines that have participated in any of the
770
* statement transactions started within the context of the normal
773
* @note In autocommit mode, this is empty.
775
TransactionContext all;
778
* The statment transaction.
780
* Contains a list of all engines participating in the given statement.
782
* @note In autocommit mode, this will be used to commit/rollback the
783
* normal transaction.
785
TransactionContext stmt;
522
801
Field *dup_field;
523
802
sigset_t signals;
1579
1850
table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1580
1851
bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1853
typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1857
TableMessageCache table_message_cache;
1860
bool storeTableMessage(const identifier::Table &identifier, message::Table &table_message);
1861
bool removeTableMessage(const identifier::Table &identifier);
1862
bool getTableMessage(const identifier::Table &identifier, message::Table &table_message);
1863
bool doesTableMessageExist(const identifier::Table &identifier);
1864
bool renameTableMessage(const identifier::Table &from, const identifier::Table &to);
1583
session::TableMessages _table_message_cache;
1868
TableMessages _table_message_cache;
1586
session::TableMessages &getMessageCache()
1871
TableMessages &getMessageCache()
1588
1873
return _table_message_cache;
1668
1952
// This lives throughout the life of Session
1669
1953
bool use_usage;
1670
session::PropertyMap life_properties;
1954
PropertyMap life_properties;
1671
1955
std::vector<table::Singular *> temporary_shares;
1672
1956
struct rusage usage;
1675
1961
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1963
} /* namespace drizzled */
1965
/** @TODO why is this in the middle of the file */
1966
#include <drizzled/select_to_file.h>
1967
#include <drizzled/select_export.h>
1968
#include <drizzled/select_dump.h>
1969
#include <drizzled/select_insert.h>
1970
#include <drizzled/select_create.h>
1971
#include <drizzled/tmp_table_param.h>
1972
#include <drizzled/select_union.h>
1973
#include <drizzled/select_subselect.h>
1974
#include <drizzled/select_singlerow_subselect.h>
1975
#include <drizzled/select_max_min_finder_subselect.h>
1976
#include <drizzled/select_exists_subselect.h>
1982
* A structure used to describe sort information
1983
* for a field or item used in ORDER BY.
1988
Field *field; /**< Field to sort */
1989
Item *item; /**< Item if not sorting fields */
1990
size_t length; /**< Length of sort field */
1991
uint32_t suffix_length; /**< Length suffix (0-4) */
1992
Item_result result_type; /**< Type of item */
1993
bool reverse; /**< if descending sort */
1994
bool need_strxnfrm; /**< If we have to use strxnfrm() */
2001
result_type(STRING_RESULT),
2008
} /* namespace drizzled */
2010
/** @TODO why is this in the middle of the file */
2012
#include <drizzled/table_ident.h>
2013
#include <drizzled/user_var_entry.h>
2014
#include <drizzled/unique.h>
2015
#include <drizzled/var.h>
2016
#include <drizzled/select_dumpvar.h>
1677
2021
/* Bits in sql_command_flags */
1679
2023
enum sql_command_flag_bits