447
414
typedef I_List<Item_change_record> Item_change_list;
451
Class that holds information about tables which were opened and locked
452
by the thread. It is also used to save/restore this information in
453
push_open_tables_state()/pop_open_tables_state().
456
class Open_tables_state
460
List of regular tables in use by this thread. Contains temporary and
461
base tables that were opened with @see open_tables().
465
List of temporary tables used by this thread. Contains user-level
466
temporary tables, created with CREATE TEMPORARY TABLE, and
467
internal temporary tables, created, e.g., to resolve a SELECT,
468
or for an intermediate table used in ALTER.
469
XXX Why are internal temporary tables added to this list?
471
Table *temporary_tables;
473
List of tables that were opened with HANDLER OPEN and are
474
still in use by this thread.
476
Table *handler_tables;
477
Table *derived_tables;
479
During a MySQL session, one can lock tables in two modes: automatic
480
or manual. In automatic mode all necessary tables are locked just before
481
statement execution, and all acquired locks are stored in 'lock'
482
member. Unlocking takes place automatically as well, when the
484
Manual mode comes into play when a user issues a 'LOCK TABLES'
485
statement. In this mode the user can only use the locked tables.
486
Trying to use any other tables will give an error. The locked tables are
487
stored in 'locked_tables' member. Manual locking is described in
488
the 'LOCK_TABLES' chapter of the MySQL manual.
489
See also lock_tables() for details.
493
Tables that were locked with explicit or implicit LOCK TABLES.
494
(Implicit LOCK TABLES happens when we are prelocking tables for
495
execution of statement which uses stored routines. See description
496
Session::prelocked_mode for more info.)
498
DRIZZLE_LOCK *locked_tables;
501
CREATE-SELECT keeps an extra lock for the table being
502
created. This field is used to keep the extra lock available for
503
lower level routines, which would otherwise miss that lock.
505
DRIZZLE_LOCK *extra_lock;
508
uint32_t current_tablenr;
511
BACKUPS_AVAIL = (1U << 0) /* There are backups available */
515
Flags with information about the open tables state.
517
uint32_t state_flags;
520
This constructor serves for creation of Open_tables_state instances
521
which are used as backup storage.
523
Open_tables_state() : state_flags(0U) { }
525
Open_tables_state(ulong version_arg);
527
void set_open_tables_state(Open_tables_state *state)
532
void reset_open_tables_state()
534
open_tables= temporary_tables= handler_tables= derived_tables= 0;
535
extra_lock= lock= locked_tables= 0;
417
#include <drizzled/open_tables_state.h>
541
419
/* Flags for the Session::system_thread variable */
542
420
enum enum_thread_type
549
This class represents the interface for internal error handlers.
550
Internal error handlers are exception handlers used by the server
553
class Internal_error_handler
556
Internal_error_handler() {}
557
virtual ~Internal_error_handler() {}
561
Handle an error condition.
562
This method can be implemented by a subclass to achieve any of the
564
- mask an error internally, prevent exposing it to the user,
565
- mask an error and throw another one instead.
566
When this method returns true, the error condition is considered
567
'handled', and will not be propagated to upper layers.
568
It is the responsability of the code installing an internal handler
569
to then check for trapped conditions, and implement logic to recover
570
from the anticipated conditions trapped during runtime.
572
This mechanism is similar to C++ try/throw/catch:
573
- 'try' correspond to <code>Session::push_internal_handler()</code>,
574
- 'throw' correspond to <code>my_error()</code>,
575
which invokes <code>my_message_sql()</code>,
576
- 'catch' correspond to checking how/if an internal handler was invoked,
577
before removing it from the exception stack with
578
<code>Session::pop_internal_handler()</code>.
580
@param sql_errno the error number
581
@param level the error level
582
@param session the calling thread
583
@return true if the error is handled
585
virtual bool handle_error(uint32_t sql_errno,
587
DRIZZLE_ERROR::enum_warning_level level,
588
Session *session) = 0;
593
Stores status of the currently executed statement.
594
Cleared at the beginning of the statement, and then
595
can hold either OK, ERROR, or EOF status.
596
Can not be assigned twice per statement.
599
class Diagnostics_area
602
enum enum_diagnostics_status
604
/** The area is cleared at start of a statement. */
606
/** Set whenever one calls my_ok(). */
608
/** Set whenever one calls my_eof(). */
610
/** Set whenever one calls my_error() or my_message(). */
612
/** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
615
/** True if status information is sent to the client. */
617
/** Set to make set_error_status after set_{ok,eof}_status possible. */
618
bool can_overwrite_status;
620
void set_ok_status(Session *session, ha_rows affected_rows_arg,
621
uint64_t last_insert_id_arg,
622
const char *message);
623
void set_eof_status(Session *session);
624
void set_error_status(Session *session, uint32_t sql_errno_arg, const char *message_arg);
626
void disable_status();
628
void reset_diagnostics_area();
630
bool is_set() const { return m_status != DA_EMPTY; }
631
bool is_error() const { return m_status == DA_ERROR; }
632
bool is_eof() const { return m_status == DA_EOF; }
633
bool is_ok() const { return m_status == DA_OK; }
634
bool is_disabled() const { return m_status == DA_DISABLED; }
635
enum_diagnostics_status status() const { return m_status; }
637
const char *message() const
638
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
640
uint32_t sql_errno() const
641
{ assert(m_status == DA_ERROR); return m_sql_errno; }
643
uint32_t server_status() const
645
assert(m_status == DA_OK || m_status == DA_EOF);
646
return m_server_status;
649
ha_rows affected_rows() const
650
{ assert(m_status == DA_OK); return m_affected_rows; }
652
uint64_t last_insert_id() const
653
{ assert(m_status == DA_OK); return m_last_insert_id; }
655
uint32_t total_warn_count() const
657
assert(m_status == DA_OK || m_status == DA_EOF);
658
return m_total_warn_count;
661
Diagnostics_area() { reset_diagnostics_area(); }
664
/** Message buffer. Can be used by OK or ERROR status. */
665
char m_message[DRIZZLE_ERRMSG_SIZE];
667
SQL error number. One of ER_ codes from share/errmsg.txt.
668
Set by set_error_status.
670
uint32_t m_sql_errno;
673
Copied from session->server_status when the diagnostics area is assigned.
674
We need this member as some places in the code use the following pattern:
675
session->server_status|= ...
677
session->server_status&= ~...
678
Assigned by OK, EOF or ERROR.
680
uint32_t m_server_status;
682
The number of rows affected by the last statement. This is
683
semantically close to session->row_count_func, but has a different
684
life cycle. session->row_count_func stores the value returned by
685
function ROW_COUNT() and is cleared only by statements that
686
update its value, such as INSERT, UPDATE, DELETE and few others.
687
This member is cleared at the beginning of the next statement.
689
We could possibly merge the two, but life cycle of session->row_count_func
692
ha_rows m_affected_rows;
694
Similarly to the previous member, this is a replacement of
695
session->first_successful_insert_id_in_prev_stmt, which is used
696
to implement LAST_INSERT_ID().
698
uint64_t m_last_insert_id;
699
/** The total number of warnings. */
700
uint m_total_warn_count;
701
enum_diagnostics_status m_status;
703
@todo: the following Session members belong here:
704
- warn_list, warn_count,
427
#include <drizzled/internal_error_handler.h>
428
#include <drizzled/diagnostics_area.h>
710
431
Storage engine specific thread local data.
1479
1200
#include <storage/myisam/myisam.h>
1482
Param to create temporary tables when doing SELECT:s
1484
This structure is copied using memcpy as a part of JOIN.
1487
class TMP_TABLE_PARAM :public Sql_alloc
1490
/* Prevent use of these (not safe because of lists and copy_field) */
1491
TMP_TABLE_PARAM(const TMP_TABLE_PARAM &);
1492
void operator=(TMP_TABLE_PARAM &);
1495
List<Item> copy_funcs;
1496
List<Item> save_copy_funcs;
1497
Copy_field *copy_field, *copy_field_end;
1498
Copy_field *save_copy_field, *save_copy_field_end;
1499
unsigned char *group_buff;
1500
Item **items_to_copy; /* Fields in tmp table */
1501
MI_COLUMNDEF *recinfo,*start_recinfo;
1503
ha_rows end_write_records;
1504
uint field_count,sum_func_count,func_count;
1505
uint32_t hidden_field_count;
1506
uint group_parts,group_length,group_null_parts;
1508
bool using_indirect_summary_function;
1509
/* If >0 convert all blob fields to varchar(convert_blob_length) */
1510
uint32_t convert_blob_length;
1511
const CHARSET_INFO *table_charset;
1514
True if GROUP BY and its aggregate functions are already computed
1515
by a table access method (e.g. by loose index scan). In this case
1516
query execution should not perform aggregation and should treat
1517
aggregate functions as normal functions.
1519
bool precomputed_group_by;
1520
bool force_copy_fields;
1522
If true, create_tmp_field called from create_tmp_table will convert
1523
all BIT fields to 64-bit longs. This is a workaround the limitation
1524
that MEMORY tables cannot index BIT columns.
1526
bool bit_fields_as_long;
1529
:copy_field(0), group_parts(0),
1530
group_length(0), group_null_parts(0), convert_blob_length(0),
1531
schema_table(0), precomputed_group_by(0), force_copy_fields(0),
1532
bit_fields_as_long(0)
1542
class select_union :public select_result_interceptor
1544
TMP_TABLE_PARAM tmp_table_param;
1548
select_union() :table(0) {}
1549
int prepare(List<Item> &list, Select_Lex_Unit *u);
1550
bool send_data(List<Item> &items);
1554
bool create_result_table(Session *session, List<Item> *column_types,
1555
bool is_distinct, uint64_t options,
1556
const char *alias, bool bit_fields_as_long);
1559
/* Base subselect interface class */
1560
class select_subselect :public select_result_interceptor
1563
Item_subselect *item;
1565
select_subselect(Item_subselect *item);
1566
bool send_data(List<Item> &items)=0;
1567
bool send_eof() { return 0; };
1570
/* Single value subselect interface class */
1571
class select_singlerow_subselect :public select_subselect
1574
select_singlerow_subselect(Item_subselect *item_arg)
1575
:select_subselect(item_arg)
1577
bool send_data(List<Item> &items);
1580
/* used in independent ALL/ANY optimisation */
1581
class select_max_min_finder_subselect :public select_subselect
1584
bool (select_max_min_finder_subselect::*op)();
1587
select_max_min_finder_subselect(Item_subselect *item_arg, bool mx)
1588
:select_subselect(item_arg), cache(0), fmax(mx)
1591
bool send_data(List<Item> &items);
1598
/* EXISTS subselect interface class */
1599
class select_exists_subselect :public select_subselect
1602
select_exists_subselect(Item_subselect *item_arg)
1603
:select_subselect(item_arg){}
1604
bool send_data(List<Item> &items);
1202
#include <drizzled/tmp_table_param.h>
1204
#include <drizzled/select_union.h>
1206
#include <drizzled/select_subselect.h>
1208
#include <drizzled/select_singlerow_subselect.h>
1209
#include <drizzled/select_max_min_finder_subselect.h>
1210
#include <drizzled/select_exists_subselect.h>
1607
1212
/* Structs used when sorting */
1625
1230
SORT_FIELD *sortorder;
1628
/* Structure for db & table in sql_yacc */
1630
class Table_ident :public Sql_alloc
1635
Select_Lex_Unit *sel;
1636
inline Table_ident(Session *session, LEX_STRING db_arg, LEX_STRING table_arg,
1638
:table(table_arg), sel((Select_Lex_Unit *)0)
1640
if (!force && (session->client_capabilities & CLIENT_NO_SCHEMA))
1645
inline Table_ident(LEX_STRING table_arg)
1646
:table(table_arg), sel((Select_Lex_Unit *)0)
1651
This constructor is used only for the case when we create a derived
1652
table. A derived table has no name and doesn't belong to any database.
1653
Later, if there was an alias specified for the table, it will be set
1654
by add_table_to_list.
1656
inline Table_ident(Select_Lex_Unit *s) : sel(s)
1658
/* We must have a table name here as this is used with add_table_to_list */
1659
db.str= empty_c_string; /* a subject to casedn_str */
1661
table.str= internal_table_name;
1664
bool is_derived_table() const { return test(sel); }
1665
inline void change_db(char *db_name)
1667
db.str= db_name; db.length= (uint) strlen(db_name);
1671
// this is needed for user_vars hash
1672
class user_var_entry
1675
user_var_entry() {} /* Remove gcc warning */
1679
query_id_t update_query_id, used_query_id;
1683
double val_real(bool *null_value);
1684
int64_t val_int(bool *null_value) const;
1685
String *val_str(bool *null_value, String *str, uint32_t decimals);
1686
my_decimal *val_decimal(bool *null_value, my_decimal *result);
1687
DTCollation collation;
1691
Unique -- class for unique (removing of duplicates).
1692
Puts all values to the TREE. If the tree becomes too big,
1693
it's dumped to the file. User can request sorted values, or
1694
just iterate through them. In the last case tree merging is performed in
1695
memory simultaneously with iteration, so it should be ~2-3x faster.
1698
class Unique :public Sql_alloc
1700
DYNAMIC_ARRAY file_ptrs;
1702
size_t max_in_memory_size;
1705
unsigned char *record_pointers;
1711
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
1712
uint32_t size_arg, size_t max_in_memory_size_arg);
1714
ulong elements_in_tree() { return tree.elements_in_tree; }
1715
inline bool unique_add(void *ptr)
1717
if (tree.elements_in_tree > max_elements && flush())
1719
return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
1722
bool get(Table *table);
1723
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
1724
size_t max_in_memory_size);
1725
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
1726
size_t max_in_memory_size)
1728
register size_t max_elems_in_tree=
1729
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
1730
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
1734
bool walk(tree_walk_action action, void *walk_action_arg);
1736
friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
1737
friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
1741
class multi_delete :public select_result_interceptor
1743
TableList *delete_tables, *table_being_deleted;
1745
ha_rows deleted, found;
1746
uint32_t num_of_tables;
1749
/* True if at least one table we delete from is transactional */
1750
bool transactional_tables;
1751
/* True if at least one table we delete from is not transactional */
1753
bool delete_while_scanning;
1755
error handling (rollback and binlogging) can happen in send_eof()
1756
so that afterward send_error() needs to find out that.
1761
multi_delete(TableList *dt, uint32_t num_of_tables);
1763
int prepare(List<Item> &list, Select_Lex_Unit *u);
1764
bool send_data(List<Item> &items);
1765
bool initialize_tables (JOIN *join);
1766
void send_error(uint32_t errcode,const char *err);
1769
virtual void abort();
1773
class multi_update :public select_result_interceptor
1775
TableList *all_tables; /* query/update command tables */
1776
TableList *leaves; /* list of leves of join table tree */
1777
TableList *update_tables, *table_being_updated;
1778
Table **tmp_tables, *main_table, *table_to_update;
1779
TMP_TABLE_PARAM *tmp_table_param;
1780
ha_rows updated, found;
1781
List <Item> *fields, *values;
1782
List <Item> **fields_for_table, **values_for_table;
1783
uint32_t table_count;
1785
List of tables referenced in the CHECK OPTION condition of
1786
the updated view excluding the updated table.
1788
List <Table> unupdated_check_opt_tables;
1789
Copy_field *copy_field;
1790
enum enum_duplicates handle_duplicates;
1791
bool do_update, trans_safe;
1792
/* True if the update operation has made a change in a transactional table */
1793
bool transactional_tables;
1796
error handling (rollback and binlogging) can happen in send_eof()
1797
so that afterward send_error() needs to find out that.
1802
multi_update(TableList *ut, TableList *leaves_list,
1803
List<Item> *fields, List<Item> *values,
1804
enum_duplicates handle_duplicates, bool ignore);
1806
int prepare(List<Item> &list, Select_Lex_Unit *u);
1807
bool send_data(List<Item> &items);
1808
bool initialize_tables (JOIN *join);
1809
void send_error(uint32_t errcode,const char *err);
1812
virtual void abort();
1815
class my_var : public Sql_alloc {
1820
enum_field_types type;
1821
my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
1822
:s(j), local(i), offset(o), type(t)
1827
class select_dumpvar :public select_result_interceptor {
1830
List<my_var> var_list;
1831
select_dumpvar() { var_list.empty(); row_count= 0;}
1832
~select_dumpvar() {}
1833
int prepare(List<Item> &list, Select_Lex_Unit *u);
1834
bool send_data(List<Item> &items);
1234
#include <drizzled/table_ident.h>
1235
#include <drizzled/user_var_entry.h>
1236
#include <drizzled/unique.h>
1237
#include <drizzled/multi_delete.h>
1238
#include <drizzled/multi_update.h>
1239
#include <drizzled/my_var.h>
1240
#include <drizzled/select_dumpvar.h>
1839
1242
/* Bits in sql_command_flags */