17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21
#ifndef DRIZZLED_SESSION_H
21
22
#define DRIZZLED_SESSION_H
24
#include "drizzled/plugin.h"
25
#include "drizzled/sql_locale.h"
26
#include "drizzled/resource_context.h"
27
#include "drizzled/cursor.h"
28
#include "drizzled/current_session.h"
29
#include "drizzled/sql_error.h"
30
#include "drizzled/file_exchange.h"
31
#include "drizzled/select_result_interceptor.h"
32
#include "drizzled/statistics_variables.h"
33
#include "drizzled/xid.h"
34
#include "drizzled/query_id.h"
35
#include "drizzled/named_savepoint.h"
36
#include "drizzled/transaction_context.h"
37
#include "drizzled/util/storable.h"
38
#include "drizzled/my_hash.h"
39
#include "drizzled/pthread_globals.h"
42
#include <sys/resource.h>
23
44
#include <algorithm>
25
#include <boost/make_shared.hpp>
26
#include <boost/thread/condition_variable.hpp>
50
#include "drizzled/identifier.h"
51
#include "drizzled/open_tables_state.h"
52
#include "drizzled/internal_error_handler.h"
53
#include "drizzled/diagnostics_area.h"
54
#include "drizzled/plugin/authorization.h"
56
#include "drizzled/catalog/instance.h"
57
#include "drizzled/catalog/local.h"
59
#include <boost/unordered_map.hpp>
61
#include <boost/thread/thread.hpp>
27
62
#include <boost/thread/mutex.hpp>
28
63
#include <boost/thread/shared_mutex.hpp>
29
#include <boost/thread/thread.hpp>
33
#include <sys/resource.h>
64
#include <boost/thread/condition_variable.hpp>
65
#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>
69
68
#define MIN_HANDSHAKE_SIZE 6
106
109
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
107
110
extern uint32_t tc_heuristic_recover;
114
Local storage for proto that are tmp table. This should be enlarged
115
to hande the entire table-share for a local table. Once Hash is done,
116
we should consider exchanging the map for it.
118
typedef std::map <std::string, message::Table> ProtoCache;
121
The COPY_INFO structure is used by INSERT/REPLACE code.
122
The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
124
If a row is inserted then the copied variable is incremented.
125
If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
126
new data differs from the old one then the copied and the updated
127
variables are incremented.
128
The touched variable is incremented if a row was touched by the update part
129
of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
130
was actually changed or not.
135
ha_rows records; /**< Number of processed records */
136
ha_rows deleted; /**< Number of deleted records */
137
ha_rows updated; /**< Number of updated records */
138
ha_rows copied; /**< Number of copied records */
140
ha_rows touched; /* Number of touched records */
141
enum enum_duplicates handle_duplicates;
142
int escape_char, last_errno;
144
/* for INSERT ... UPDATE */
145
List<Item> *update_fields;
146
List<Item> *update_values;
147
/* for VIEW ... WITH CHECK OPTION */
165
} /* namespace drizzled */
167
/** @TODO why is this in the middle of the file */
168
#include <drizzled/lex_column.h>
109
176
#define Session_SENTRY_MAGIC 0xfeedd1ff
110
177
#define Session_SENTRY_GONE 0xdeadbeef
112
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
179
struct drizzle_system_variables
181
drizzle_system_variables()
184
How dynamically allocated system variables are handled:
186
The global_system_variables and max_system_variables are "authoritative"
187
They both should have the same 'version' and 'size'.
188
When attempting to access a dynamic variable, if the session version
189
is out of date, then the session version is updated and realloced if
190
neccessary and bytes copied from global to make up for missing data.
192
ulong dynamic_variables_version;
193
char * dynamic_variables_ptr;
194
uint32_t dynamic_variables_head; /* largest valid variable offset */
195
uint32_t dynamic_variables_size; /* how many bytes are in use */
197
uint64_t myisam_max_extra_sort_file_size;
198
uint64_t max_heap_table_size;
199
uint64_t tmp_table_size;
200
ha_rows select_limit;
201
ha_rows max_join_size;
202
uint64_t auto_increment_increment;
203
uint64_t auto_increment_offset;
204
uint64_t bulk_insert_buff_size;
205
uint64_t join_buff_size;
206
uint32_t max_allowed_packet;
207
uint64_t max_error_count;
208
uint64_t max_length_for_sort_data;
209
size_t max_sort_length;
210
uint64_t min_examined_row_limit;
211
bool optimizer_prune_level;
214
uint32_t optimizer_search_depth;
215
uint32_t div_precincrement;
216
uint64_t preload_buff_size;
217
uint32_t read_buff_size;
218
uint32_t read_rnd_buff_size;
219
bool replicate_query;
220
size_t sortbuff_size;
221
uint32_t thread_handling;
222
uint32_t tx_isolation;
223
size_t transaction_message_threshold;
224
uint32_t completion_type;
225
/* Determines which non-standard SQL behaviour should be enabled */
227
uint64_t max_seeks_for_key;
228
size_t range_alloc_block_size;
229
uint32_t query_alloc_block_size;
230
uint32_t query_prealloc_size;
231
uint64_t group_concat_max_len;
232
uint64_t pseudo_thread_id;
234
plugin::StorageEngine *storage_engine;
236
/* Only charset part of these variables is sensible */
237
const CHARSET_INFO *character_set_filesystem;
239
/* Both charset and collation parts of these variables are important */
240
const CHARSET_INFO *collation_server;
242
inline const CHARSET_INFO *getCollation(void)
244
return collation_server;
248
MY_LOCALE *lc_time_names;
250
Time_zone *time_zone;
253
extern struct drizzle_system_variables global_system_variables;
255
} /* namespace drizzled */
257
#include "drizzled/sql_lex.h"
262
void mark_transaction_to_rollback(Session *session, bool all);
265
Storage engine specific thread local data.
270
Storage engine specific thread local data.
271
Lifetime: one user connection.
275
* Resource contexts for both the "statement" and "normal"
278
* Resource context at index 0:
280
* Life time: one statement within a transaction. If @@autocommit is
281
* on, also represents the entire transaction.
283
* Resource context at index 1:
285
* Life time: one transaction within a connection.
289
* If the storage engine does not participate in a transaction,
290
* there will not be a resource context.
292
drizzled::ResourceContext resource_context[2];
294
Ha_data() :ha_ptr(NULL) {}
115
298
* Represents a client connection to the database server.
517
719
ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
518
720
size_t index= 0);
520
session::Transactions transaction;
723
* Structure used to manage "statement transactions" and
724
* "normal transactions". In autocommit mode, the normal transaction is
725
* equivalent to the statement transaction.
727
* Storage engines will be registered here when they participate in
728
* a transaction. No engine is registered more than once.
730
struct st_transactions {
731
std::deque<NamedSavepoint> savepoints;
734
* The normal transaction (since BEGIN WORK).
736
* Contains a list of all engines that have participated in any of the
737
* statement transactions started within the context of the normal
740
* @note In autocommit mode, this is empty.
742
TransactionContext all;
745
* The statment transaction.
747
* Contains a list of all engines participating in the given statement.
749
* @note In autocommit mode, this will be used to commit/rollback the
750
* normal transaction.
752
TransactionContext stmt;
522
768
Field *dup_field;
523
769
sigset_t signals;
1579
1798
table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1580
1799
bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1801
typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1805
TableMessageCache table_message_cache;
1808
bool storeTableMessage(const identifier::Table &identifier, message::Table &table_message);
1809
bool removeTableMessage(const identifier::Table &identifier);
1810
bool getTableMessage(const identifier::Table &identifier, message::Table &table_message);
1811
bool doesTableMessageExist(const identifier::Table &identifier);
1812
bool renameTableMessage(const identifier::Table &from, const identifier::Table &to);
1583
session::TableMessages _table_message_cache;
1816
TableMessages _table_message_cache;
1586
session::TableMessages &getMessageCache()
1819
TableMessages &getMessageCache()
1588
1821
return _table_message_cache;
1668
1900
// This lives throughout the life of Session
1669
1901
bool use_usage;
1670
session::PropertyMap life_properties;
1902
PropertyMap life_properties;
1671
1903
std::vector<table::Singular *> temporary_shares;
1672
1904
struct rusage usage;
1675
1909
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1911
} /* namespace drizzled */
1913
/** @TODO why is this in the middle of the file */
1914
#include <drizzled/select_to_file.h>
1915
#include <drizzled/select_export.h>
1916
#include <drizzled/select_dump.h>
1917
#include <drizzled/select_insert.h>
1918
#include <drizzled/select_create.h>
1919
#include <drizzled/tmp_table_param.h>
1920
#include <drizzled/select_union.h>
1921
#include <drizzled/select_subselect.h>
1922
#include <drizzled/select_singlerow_subselect.h>
1923
#include <drizzled/select_max_min_finder_subselect.h>
1924
#include <drizzled/select_exists_subselect.h>
1930
* A structure used to describe sort information
1931
* for a field or item used in ORDER BY.
1936
Field *field; /**< Field to sort */
1937
Item *item; /**< Item if not sorting fields */
1938
size_t length; /**< Length of sort field */
1939
uint32_t suffix_length; /**< Length suffix (0-4) */
1940
Item_result result_type; /**< Type of item */
1941
bool reverse; /**< if descending sort */
1942
bool need_strxnfrm; /**< If we have to use strxnfrm() */
1949
result_type(STRING_RESULT),
1956
} /* namespace drizzled */
1958
/** @TODO why is this in the middle of the file */
1960
#include <drizzled/table_ident.h>
1961
#include <drizzled/user_var_entry.h>
1962
#include <drizzled/unique.h>
1963
#include <drizzled/var.h>
1964
#include <drizzled/select_dumpvar.h>
1677
1969
/* Bits in sql_command_flags */
1679
1971
enum sql_command_flag_bits