~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_class.h

  • Committer: Brian Aker
  • Date: 2008-08-12 03:12:57 UTC
  • Revision ID: brian@tangent.org-20080812031257-ln3uk87y1r22byeg
First pass of new sql_db.cc work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
19
15
 
20
16
 
21
17
/* Classes in mysql */
52
48
 
53
49
#define TC_HEURISTIC_RECOVER_COMMIT   1
54
50
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
55
 
extern uint32_t tc_heuristic_recover;
 
51
extern uint tc_heuristic_recover;
56
52
 
57
53
typedef struct st_user_var_events
58
54
{
60
56
  char *value;
61
57
  ulong length;
62
58
  Item_result type;
63
 
  uint32_t charset_number;
 
59
  uint charset_number;
64
60
} BINLOG_USER_VAR_EVENT;
65
61
 
66
62
#define RP_LOCK_LOG_IS_ALREADY_LOCKED 1
98
94
class Key_part_spec :public Sql_alloc {
99
95
public:
100
96
  LEX_STRING field_name;
101
 
  uint32_t length;
102
 
  Key_part_spec(const LEX_STRING &name, uint32_t len)
 
97
  uint length;
 
98
  Key_part_spec(const LEX_STRING &name, uint len)
103
99
    : field_name(name), length(len)
104
100
  {}
105
 
  Key_part_spec(const char *name, const size_t name_len, uint32_t len)
 
101
  Key_part_spec(const char *name, const size_t name_len, uint len)
106
102
    : length(len)
107
103
  { field_name.str= (char *)name; field_name.length= name_len; }
108
104
  bool operator==(const Key_part_spec& other) const;
198
194
 
199
195
  Table_ident *ref_table;
200
196
  List<Key_part_spec> ref_columns;
201
 
  uint32_t delete_opt, update_opt, match_opt;
 
197
  uint delete_opt, update_opt, match_opt;
202
198
  Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
203
199
              Table_ident *table,   List<Key_part_spec> &ref_cols,
204
 
              uint32_t delete_opt_arg, uint32_t update_opt_arg, uint32_t match_opt_arg)
 
200
              uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
205
201
    :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
206
202
    ref_table(table), ref_columns(ref_cols),
207
203
    delete_opt(delete_opt_arg), update_opt(update_opt_arg),
218
214
 
219
215
typedef struct st_mysql_lock
220
216
{
221
 
  Table **table;
222
 
  uint32_t table_count,lock_count;
 
217
  TABLE **table;
 
218
  uint table_count,lock_count;
223
219
  THR_LOCK_DATA **locks;
224
 
} DRIZZLE_LOCK;
 
220
} MYSQL_LOCK;
225
221
 
226
222
 
227
223
class LEX_COLUMN : public Sql_alloc
228
224
{
229
225
public:
230
226
  String column;
231
 
  uint32_t rights;
 
227
  uint rights;
232
228
  LEX_COLUMN (const String& x,const  uint& y ): column (x),rights (y) {}
233
229
};
234
230
 
 
231
#include "sql_lex.h"                            /* Must be here */
 
232
 
235
233
class select_result;
236
234
class Time_zone;
237
235
 
253
251
  */ 
254
252
  ulong dynamic_variables_version;
255
253
  char* dynamic_variables_ptr;
256
 
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
257
 
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
 
254
  uint dynamic_variables_head;  /* largest valid variable offset */
 
255
  uint dynamic_variables_size;  /* how many bytes are in use */
258
256
  
259
257
  uint64_t myisam_max_extra_sort_file_size;
260
258
  uint64_t myisam_max_sort_file_size;
357
355
 
358
356
};
359
357
 
360
 
#include "sql_lex.h"  /* only for SQLCOM_END */
361
358
 
362
359
/* per thread status variables */
363
360
 
442
439
 
443
440
void mark_transaction_to_rollback(THD *thd, bool all);
444
441
 
445
 
#ifdef DRIZZLE_SERVER
 
442
#ifdef MYSQL_SERVER
 
443
 
 
444
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
446
445
 
447
446
class Query_arena
448
447
{
453
452
  */
454
453
  Item *free_list;
455
454
  MEM_ROOT *mem_root;                   // Pointer to current memroot
456
 
 
457
 
  Query_arena(MEM_ROOT *mem_root_arg) :
458
 
    free_list(0), mem_root(mem_root_arg)
459
 
  { }
 
455
  bool is_backup_arena; /* True if this arena is used for backup. */
 
456
 
 
457
  /*
 
458
    The states relfects three diffrent life cycles for three
 
459
    different types of statements:
 
460
    Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
 
461
    Stored procedure:   INITIALIZED_FOR_SP -> EXECUTED.
 
462
    Other statements:   CONVENTIONAL_EXECUTION never changes.
 
463
  */
 
464
  enum enum_state
 
465
  {
 
466
    INITIALIZED= 0,
 
467
    CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
 
468
  };
 
469
 
 
470
  enum_state state;
 
471
 
 
472
  Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
 
473
    free_list(0), mem_root(mem_root_arg), state(state_arg)
 
474
  { INIT_ARENA_DBUG_INFO; }
460
475
  /*
461
476
    This constructor is used only when Query_arena is created as
462
477
    backup storage for another instance of Query_arena.
463
478
  */
464
 
  Query_arena() { }
 
479
  Query_arena() { INIT_ARENA_DBUG_INFO; }
465
480
 
466
481
  virtual ~Query_arena() {};
467
482
 
 
483
  inline bool is_conventional() const
 
484
  { assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
 
485
 
468
486
  inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
469
487
  inline void* calloc(size_t size)
470
488
  {
479
497
  { return strmake_root(mem_root,str,size); }
480
498
  inline void *memdup(const void *str, size_t size)
481
499
  { return memdup_root(mem_root,str,size); }
482
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
 
500
  inline void *memdup_w_gap(const void *str, size_t size, uint gap)
483
501
  {
484
502
    void *ptr;
485
503
    if ((ptr= alloc_root(mem_root,size+gap)))
487
505
    return ptr;
488
506
  }
489
507
 
 
508
  void set_query_arena(Query_arena *set);
 
509
 
490
510
  void free_items();
 
511
  /* Close the active state associated with execution of this statement */
 
512
  virtual void cleanup_stmt();
491
513
};
492
514
 
493
515
 
528
550
  */
529
551
  enum enum_mark_columns mark_used_columns;
530
552
 
 
553
  LEX_STRING name; /* name for named prepared statements */
531
554
  LEX *lex;                                     // parse tree descriptor
532
555
  /*
533
556
    Points to the query associated with this statement. It's const, but
568
591
  */
569
592
 
570
593
  char *db;
571
 
  uint32_t db_length;
 
594
  uint db_length;
572
595
 
573
596
public:
574
597
 
575
598
  /* This constructor is called for backup statements */
576
599
  Statement() {}
577
600
 
578
 
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
 
601
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
 
602
            enum enum_state state_arg, ulong id_arg);
579
603
  ~Statement() {}
 
604
 
 
605
  /* Assign execution context (note: not all members) of given stmt to self */
 
606
  void set_statement(Statement *stmt);
 
607
  void set_n_backup_statement(Statement *stmt, Statement *backup);
 
608
  void restore_backup_statement(Statement *stmt, Statement *backup);
580
609
};
581
610
 
582
611
struct st_savepoint {
583
612
  struct st_savepoint *prev;
584
613
  char                *name;
585
 
  uint32_t                 length;
 
614
  uint                 length;
586
615
  Ha_trx_info         *ha_list;
587
616
};
588
617
 
657
686
    List of regular tables in use by this thread. Contains temporary and
658
687
    base tables that were opened with @see open_tables().
659
688
  */
660
 
  Table *open_tables;
 
689
  TABLE *open_tables;
661
690
  /**
662
691
    List of temporary tables used by this thread. Contains user-level
663
692
    temporary tables, created with CREATE TEMPORARY TABLE, and
665
694
    or for an intermediate table used in ALTER.
666
695
    XXX Why are internal temporary tables added to this list?
667
696
  */
668
 
  Table *temporary_tables;
 
697
  TABLE *temporary_tables;
669
698
  /**
670
699
    List of tables that were opened with HANDLER OPEN and are
671
700
    still in use by this thread.
672
701
  */
673
 
  Table *handler_tables;
674
 
  Table *derived_tables;
 
702
  TABLE *handler_tables;
 
703
  TABLE *derived_tables;
675
704
  /*
676
705
    During a MySQL session, one can lock tables in two modes: automatic
677
706
    or manual. In automatic mode all necessary tables are locked just before
685
714
    the 'LOCK_TABLES' chapter of the MySQL manual.
686
715
    See also lock_tables() for details.
687
716
  */
688
 
  DRIZZLE_LOCK *lock;
 
717
  MYSQL_LOCK *lock;
689
718
  /*
690
719
    Tables that were locked with explicit or implicit LOCK TABLES.
691
720
    (Implicit LOCK TABLES happens when we are prelocking tables for
692
721
     execution of statement which uses stored routines. See description
693
722
     THD::prelocked_mode for more info.)
694
723
  */
695
 
  DRIZZLE_LOCK *locked_tables;
 
724
  MYSQL_LOCK *locked_tables;
696
725
 
697
726
  /*
698
727
    CREATE-SELECT keeps an extra lock for the table being
699
728
    created. This field is used to keep the extra lock available for
700
729
    lower level routines, which would otherwise miss that lock.
701
730
   */
702
 
  DRIZZLE_LOCK *extra_lock;
 
731
  MYSQL_LOCK *extra_lock;
703
732
 
704
733
  ulong version;
705
 
  uint32_t current_tablenr;
 
734
  uint current_tablenr;
706
735
 
707
736
  enum enum_flags {
708
737
    BACKUPS_AVAIL = (1U << 0)     /* There are backups available */
711
740
  /*
712
741
    Flags with information about the open tables state.
713
742
  */
714
 
  uint32_t state_flags;
 
743
  uint state_flags;
715
744
 
716
745
  /*
717
746
    This constructor serves for creation of Open_tables_state instances
734
763
  }
735
764
};
736
765
 
 
766
/**
 
767
  @class Sub_statement_state
 
768
  @brief Used to save context when executing a function or trigger
 
769
*/
 
770
 
 
771
/* Defines used for Sub_statement_state::in_sub_stmt */
 
772
 
 
773
#define SUB_STMT_TRIGGER 1
 
774
#define SUB_STMT_FUNCTION 2
 
775
 
 
776
 
 
777
class Sub_statement_state
 
778
{
 
779
public:
 
780
  uint64_t options;
 
781
  uint64_t first_successful_insert_id_in_prev_stmt;
 
782
  uint64_t first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
 
783
  Discrete_interval auto_inc_interval_for_cur_row;
 
784
  Discrete_intervals_list auto_inc_intervals_forced;
 
785
  uint64_t limit_found_rows;
 
786
  ha_rows    cuted_fields, sent_row_count, examined_row_count;
 
787
  ulong client_capabilities;
 
788
  uint in_sub_stmt;
 
789
  bool enable_slow_log;
 
790
  bool last_insert_id_used;
 
791
  SAVEPOINT *savepoints;
 
792
};
 
793
 
737
794
 
738
795
/* Flags for the THD::system_thread variable */
739
796
enum enum_thread_type
781
838
    @param thd the calling thread
782
839
    @return true if the error is handled
783
840
  */
784
 
  virtual bool handle_error(uint32_t sql_errno,
 
841
  virtual bool handle_error(uint sql_errno,
785
842
                            const char *message,
786
843
                            DRIZZLE_ERROR::enum_warning_level level,
787
844
                            THD *thd) = 0;
820
877
                     uint64_t last_insert_id_arg,
821
878
                     const char *message);
822
879
  void set_eof_status(THD *thd);
823
 
  void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
 
880
  void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
824
881
 
825
882
  void disable_status();
826
883
 
836
893
  const char *message() const
837
894
  { assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
838
895
 
839
 
  uint32_t sql_errno() const
 
896
  uint sql_errno() const
840
897
  { assert(m_status == DA_ERROR); return m_sql_errno; }
841
898
 
842
 
  uint32_t server_status() const
 
899
  uint server_status() const
843
900
  {
844
901
    assert(m_status == DA_OK || m_status == DA_EOF);
845
902
    return m_server_status;
851
908
  uint64_t last_insert_id() const
852
909
  { assert(m_status == DA_OK); return m_last_insert_id; }
853
910
 
854
 
  uint32_t total_warn_count() const
 
911
  uint total_warn_count() const
855
912
  {
856
913
    assert(m_status == DA_OK || m_status == DA_EOF);
857
914
    return m_total_warn_count;
866
923
    SQL error number. One of ER_ codes from share/errmsg.txt.
867
924
    Set by set_error_status.
868
925
  */
869
 
  uint32_t m_sql_errno;
 
926
  uint m_sql_errno;
870
927
 
871
928
  /**
872
929
    Copied from thd->server_status when the diagnostics area is assigned.
876
933
    thd->server_status&= ~...
877
934
    Assigned by OK, EOF or ERROR.
878
935
  */
879
 
  uint32_t m_server_status;
 
936
  uint m_server_status;
880
937
  /**
881
938
    The number of rows affected by the last statement. This is
882
939
    semantically close to thd->row_count_func, but has a different
1004
1061
    Set it using the  thd_proc_info(THD *thread, const char *message)
1005
1062
    macro/function.
1006
1063
  */
1007
 
  void        set_proc_info(const char *info) { proc_info= info; }
1008
 
  const char* get_proc_info() const { return proc_info; }
 
1064
#define THD_SET_PROC_INFO(thd, info) \
 
1065
    (thd)->proc_info= (info)
 
1066
 
 
1067
  inline const char* get_proc_info() { return proc_info;}
 
1068
 
 
1069
  /* left public for the the storage engines, please avoid direct use */
 
1070
  const char *proc_info;
1009
1071
 
1010
1072
  /*
1011
1073
    Used in error messages to tell user in what part of MySQL we found an
1024
1086
    points to a lock object if the lock is present. See item_func.cc and
1025
1087
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK. 
1026
1088
  */
1027
 
  uint32_t dbug_sentry; // watch out for memory corruption
 
1089
  uint dbug_sentry; // watch out for memory corruption
1028
1090
  struct st_my_thread_var *mysys_var;
1029
1091
  /*
1030
1092
    Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1042
1104
  thr_lock_type update_lock_default;
1043
1105
 
1044
1106
  /* <> 0 if we are inside of trigger or stored function. */
1045
 
  uint32_t in_sub_stmt;
 
1107
  uint in_sub_stmt;
1046
1108
 
1047
1109
  /* container for handler's private per-connection data */
1048
1110
  Ha_data ha_data[MAX_HA];
1049
1111
 
1050
1112
  /* Place to store various things */
1051
1113
  void *thd_marker;
 
1114
#ifndef MYSQL_CLIENT
1052
1115
  int binlog_setup_trx_data();
1053
1116
 
1054
1117
  /*
1056
1119
  */
1057
1120
  void binlog_start_trans_and_stmt();
1058
1121
  void binlog_set_stmt_begin();
1059
 
  int binlog_write_table_map(Table *table, bool is_transactional);
1060
 
  int binlog_write_row(Table* table, bool is_transactional,
1061
 
                       const unsigned char *new_data);
1062
 
  int binlog_delete_row(Table* table, bool is_transactional,
1063
 
                        const unsigned char *old_data);
1064
 
  int binlog_update_row(Table* table, bool is_transactional,
1065
 
                        const unsigned char *old_data, const unsigned char *new_data);
 
1122
  int binlog_write_table_map(TABLE *table, bool is_transactional);
 
1123
  int binlog_write_row(TABLE* table, bool is_transactional,
 
1124
                       const uchar *new_data);
 
1125
  int binlog_delete_row(TABLE* table, bool is_transactional,
 
1126
                        const uchar *old_data);
 
1127
  int binlog_update_row(TABLE* table, bool is_transactional,
 
1128
                        const uchar *old_data, const uchar *new_data);
1066
1129
 
1067
1130
  void set_server_id(uint32_t sid) { server_id = sid; }
1068
1131
 
1070
1133
    Member functions to handle pending event for row-level logging.
1071
1134
  */
1072
1135
  template <class RowsEventT> Rows_log_event*
1073
 
    binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
1136
    binlog_prepare_pending_rows_event(TABLE* table, uint32_t serv_id,
1074
1137
                                      size_t needed,
1075
1138
                                      bool is_transactional,
1076
1139
                                      RowsEventT* hint);
1079
1142
  int binlog_flush_pending_rows_event(bool stmt_end);
1080
1143
 
1081
1144
private:
1082
 
  uint32_t binlog_table_maps; // Number of table maps currently in the binlog
 
1145
  uint binlog_table_maps; // Number of table maps currently in the binlog
1083
1146
 
1084
1147
  enum enum_binlog_flag {
1085
1148
    BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1092
1155
   */
1093
1156
  uint32_t binlog_flags;
1094
1157
public:
1095
 
  uint32_t get_binlog_table_maps() const {
 
1158
  uint get_binlog_table_maps() const {
1096
1159
    return binlog_table_maps;
1097
1160
  }
1098
1161
  void clear_binlog_table_maps() {
1099
1162
    binlog_table_maps= 0;
1100
1163
  }
 
1164
#endif /* MYSQL_CLIENT */
1101
1165
 
1102
1166
public:
1103
1167
 
1114
1178
       List contain only transactional tables, that not invalidated in query
1115
1179
       cache (instead of full list of changed in transaction tables).
1116
1180
    */
1117
 
    CHANGED_TableList* changed_tables;
 
1181
    CHANGED_TABLE_LIST* changed_tables;
1118
1182
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
1119
1183
    void cleanup()
1120
1184
    {
1131
1195
  } transaction;
1132
1196
  Field      *dup_field;
1133
1197
  sigset_t signals;
 
1198
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1199
  Vio* active_vio;
 
1200
#endif
1134
1201
  /*
1135
1202
    This is to track items changed during execution of a prepared
1136
1203
    statement/stored procedure. It's created by
1140
1207
  */
1141
1208
  Item_change_list change_list;
1142
1209
 
 
1210
  /*
 
1211
    A permanent memory area of the statement. For conventional
 
1212
    execution, the parsed tree and execution runtime reside in the same
 
1213
    memory root. In this case stmt_arena points to THD. In case of
 
1214
    a prepared statement or a stored procedure statement, thd->mem_root
 
1215
    conventionally points to runtime memory, and thd->stmt_arena
 
1216
    points to the memory of the PS/SP, where the parsed tree of the
 
1217
    statement resides. Whenever you need to perform a permanent
 
1218
    transformation of a parsed tree, you should allocate new memory in
 
1219
    stmt_arena, to allow correct re-execution of PS/SP.
 
1220
    Note: in the parser, stmt_arena == thd, even for PS/SP.
 
1221
  */
 
1222
  Query_arena *stmt_arena;
1143
1223
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
1144
1224
  bool arg_of_last_insert_id_function;
1145
1225
  /*
1337
1417
  uint       tmp_table, global_read_lock;
1338
1418
  uint       server_status,open_options;
1339
1419
  enum enum_thread_type system_thread;
1340
 
  uint32_t       select_number;             //number of select (used for EXPLAIN)
 
1420
  uint       select_number;             //number of select (used for EXPLAIN)
1341
1421
  /* variables.transaction_isolation is reset to this after each commit */
1342
1422
  enum_tx_isolation session_tx_isolation;
1343
1423
  enum_check_fields count_cuted_fields;
1484
1564
  void cleanup(void);
1485
1565
  void cleanup_after_query();
1486
1566
  bool store_globals();
 
1567
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1568
  inline void set_active_vio(Vio* vio)
 
1569
  {
 
1570
    pthread_mutex_lock(&LOCK_delete);
 
1571
    active_vio = vio;
 
1572
    pthread_mutex_unlock(&LOCK_delete);
 
1573
  }
 
1574
  inline void clear_active_vio()
 
1575
  {
 
1576
    pthread_mutex_lock(&LOCK_delete);
 
1577
    active_vio = 0;
 
1578
    pthread_mutex_unlock(&LOCK_delete);
 
1579
  }
 
1580
  void close_active_vio();
 
1581
#endif
1487
1582
  void awake(THD::killed_state state_to_set);
1488
1583
 
 
1584
#ifndef MYSQL_CLIENT
1489
1585
  enum enum_binlog_query_type {
1490
1586
    /*
1491
1587
      The query can be logged row-based or statement-based
1501
1597
      The query represents a change to a table in the "mysql"
1502
1598
      database and is currently mapped to ROW_QUERY_TYPE.
1503
1599
    */
1504
 
    DRIZZLE_QUERY_TYPE,
 
1600
    MYSQL_QUERY_TYPE,
1505
1601
    QUERY_TYPE_COUNT
1506
1602
  };
1507
1603
  
1509
1605
                   char const *query, ulong query_len,
1510
1606
                   bool is_trans, bool suppress_use,
1511
1607
                   THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
 
1608
#endif
1512
1609
 
1513
1610
  /*
1514
1611
    For enter_cond() / exit_cond() to work the mutex must be got before
1577
1674
  }
1578
1675
 
1579
1676
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1580
 
                              const char* str, uint32_t length,
 
1677
                              const char* str, uint length,
1581
1678
                              bool allocate_lex_string);
1582
1679
 
1583
1680
  bool convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1584
 
                      const char *from, uint32_t from_length,
 
1681
                      const char *from, uint from_length,
1585
1682
                      const CHARSET_INFO * const from_cs);
1586
1683
 
1587
1684
  bool convert_string(String *s, const CHARSET_INFO * const from_cs, const CHARSET_INFO * const to_cs);
1588
1685
 
1589
 
  void add_changed_table(Table *table);
 
1686
  void add_changed_table(TABLE *table);
1590
1687
  void add_changed_table(const char *key, long key_length);
1591
 
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
 
1688
  CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1592
1689
  int send_explain_fields(select_result *result);
1593
1690
  /**
1594
1691
    Clear the current error, if any.
1605
1702
    return;
1606
1703
  }
1607
1704
  inline bool vio_ok() const { return net.vio != 0; }
1608
 
 
 
1705
  /** Return false if connection to client is broken. */
 
1706
  bool vio_is_connected();
1609
1707
  /**
1610
1708
    Mark the current error as fatal. Warning: this does not
1611
1709
    set any error, it sets a property of the error, so must be
1635
1733
 
1636
1734
  void change_item_tree(Item **place, Item *new_value)
1637
1735
  {
 
1736
    /* TODO: check for OOM condition here */
 
1737
    if (!stmt_arena->is_conventional())
 
1738
      nocheck_register_item_tree_change(place, *place, mem_root);
1638
1739
    *place= new_value;
1639
1740
  }
1640
1741
  void nocheck_register_item_tree_change(Item **place, Item *old_value,
1660
1761
  void set_status_var_init();
1661
1762
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
1662
1763
  void restore_backup_open_tables_state(Open_tables_state *backup);
 
1764
  void restore_sub_statement_state(Sub_statement_state *backup);
 
1765
  void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
 
1766
  void restore_active_arena(Query_arena *set, Query_arena *backup);
1663
1767
 
1664
1768
  inline void set_current_stmt_binlog_row_based_if_mixed()
1665
1769
  {
1738
1842
      memcpy(db, new_db, new_db_len+1);
1739
1843
    else
1740
1844
    {
1741
 
      if (db)
1742
 
        free(db);
 
1845
      x_free(db);
1743
1846
      if (new_db)
1744
1847
        db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR));
1745
1848
      else
1786
1889
    @param level the error level
1787
1890
    @return true if the error is handled
1788
1891
  */
1789
 
  virtual bool handle_error(uint32_t sql_errno, const char *message,
 
1892
  virtual bool handle_error(uint sql_errno, const char *message,
1790
1893
                            DRIZZLE_ERROR::enum_warning_level level);
1791
1894
 
1792
1895
  /**
1795
1898
  void pop_internal_handler();
1796
1899
 
1797
1900
private:
1798
 
  const char *proc_info;
1799
 
 
1800
1901
  /** The current internal error handler for this thread, or NULL. */
1801
1902
  Internal_error_handler *m_internal_handler;
1802
1903
  /**
1890
1991
    we need to know number of columns in the result set (if
1891
1992
    there is a result set) apart from sending columns metadata.
1892
1993
  */
1893
 
  virtual uint32_t field_count(List<Item> &fields) const
 
1994
  virtual uint field_count(List<Item> &fields) const
1894
1995
  { return fields.elements; }
1895
 
  virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
 
1996
  virtual bool send_fields(List<Item> &list, uint flags)=0;
1896
1997
  virtual bool send_data(List<Item> &items)=0;
1897
1998
  virtual bool initialize_tables (JOIN  __attribute__((unused)) *join=0)
1898
1999
  { return 0; }
1899
 
  virtual void send_error(uint32_t errcode,const char *err);
 
2000
  virtual void send_error(uint errcode,const char *err);
1900
2001
  virtual bool send_eof()=0;
1901
2002
  /**
1902
2003
    Check if this query returns a result set and therefore is allowed in
1927
2028
{
1928
2029
public:
1929
2030
  select_result_interceptor() {}              /* Remove gcc warning */
1930
 
  uint32_t field_count(List<Item> &fields __attribute__((unused))) const
 
2031
  uint field_count(List<Item> &fields __attribute__((unused))) const
1931
2032
  { return 0; }
1932
2033
  bool send_fields(List<Item> &fields __attribute__((unused)),
1933
 
                   uint32_t flag __attribute__((unused))) { return false; }
 
2034
                   uint flag __attribute__((unused))) { return false; }
1934
2035
};
1935
2036
 
1936
2037
 
1943
2044
  bool is_result_set_started;
1944
2045
public:
1945
2046
  select_send() :is_result_set_started(false) {}
1946
 
  bool send_fields(List<Item> &list, uint32_t flags);
 
2047
  bool send_fields(List<Item> &list, uint flags);
1947
2048
  bool send_data(List<Item> &items);
1948
2049
  bool send_eof();
1949
2050
  virtual bool check_simple_select() const { return false; }
1964
2065
  select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1965
2066
  { path[0]=0; }
1966
2067
  ~select_to_file();
1967
 
  void send_error(uint32_t errcode,const char *err);
 
2068
  void send_error(uint errcode,const char *err);
1968
2069
  bool send_eof();
1969
2070
  void cleanup();
1970
2071
};
1980
2081
 
1981
2082
 
1982
2083
class select_export :public select_to_file {
1983
 
  uint32_t field_term_length;
 
2084
  uint field_term_length;
1984
2085
  int field_sep_char,escape_char,line_sep_char;
1985
2086
  int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1986
2087
  /*
2020
2121
 
2021
2122
class select_insert :public select_result_interceptor {
2022
2123
 public:
2023
 
  TableList *table_list;
2024
 
  Table *table;
 
2124
  TABLE_LIST *table_list;
 
2125
  TABLE *table;
2025
2126
  List<Item> *fields;
2026
2127
  uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2027
2128
  COPY_INFO info;
2028
2129
  bool insert_into_view;
2029
 
  select_insert(TableList *table_list_par,
2030
 
                Table *table_par, List<Item> *fields_par,
 
2130
  select_insert(TABLE_LIST *table_list_par,
 
2131
                TABLE *table_par, List<Item> *fields_par,
2031
2132
                List<Item> *update_fields, List<Item> *update_values,
2032
2133
                enum_duplicates duplic, bool ignore);
2033
2134
  ~select_insert();
2036
2137
  bool send_data(List<Item> &items);
2037
2138
  virtual void store_values(List<Item> &values);
2038
2139
  virtual bool can_rollback_data() { return 0; }
2039
 
  void send_error(uint32_t errcode,const char *err);
 
2140
  void send_error(uint errcode,const char *err);
2040
2141
  bool send_eof();
2041
2142
  void abort();
2042
2143
  /* not implemented: select_insert is never re-used in prepared statements */
2045
2146
 
2046
2147
 
2047
2148
class select_create: public select_insert {
2048
 
  order_st *group;
2049
 
  TableList *create_table;
 
2149
  ORDER *group;
 
2150
  TABLE_LIST *create_table;
2050
2151
  HA_CREATE_INFO *create_info;
2051
 
  TableList *select_tables;
 
2152
  TABLE_LIST *select_tables;
2052
2153
  Alter_info *alter_info;
2053
2154
  Field **field;
2054
2155
  /* lock data for tmp table */
2055
 
  DRIZZLE_LOCK *m_lock;
 
2156
  MYSQL_LOCK *m_lock;
2056
2157
  /* m_lock or thd->extra_lock */
2057
 
  DRIZZLE_LOCK **m_plock;
 
2158
  MYSQL_LOCK **m_plock;
2058
2159
public:
2059
 
  select_create (TableList *table_arg,
 
2160
  select_create (TABLE_LIST *table_arg,
2060
2161
                 HA_CREATE_INFO *create_info_par,
2061
2162
                 Alter_info *alter_info_arg,
2062
2163
                 List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2063
 
                 TableList *select_tables_arg)
 
2164
                 TABLE_LIST *select_tables_arg)
2064
2165
    :select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2065
2166
    create_table(table_arg),
2066
2167
    create_info(create_info_par),
2070
2171
    {}
2071
2172
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2072
2173
 
2073
 
  void binlog_show_create_table(Table **tables, uint32_t count);
 
2174
  void binlog_show_create_table(TABLE **tables, uint count);
2074
2175
  void store_values(List<Item> &values);
2075
 
  void send_error(uint32_t errcode,const char *err);
 
2176
  void send_error(uint errcode,const char *err);
2076
2177
  bool send_eof();
2077
2178
  void abort();
2078
2179
  virtual bool can_rollback_data() { return 1; }
2103
2204
  List<Item> save_copy_funcs;
2104
2205
  Copy_field *copy_field, *copy_field_end;
2105
2206
  Copy_field *save_copy_field, *save_copy_field_end;
2106
 
  unsigned char     *group_buff;
 
2207
  uchar     *group_buff;
2107
2208
  Item      **items_to_copy;                    /* Fields in tmp table */
2108
2209
  MI_COLUMNDEF *recinfo,*start_recinfo;
2109
2210
  KEY *keyinfo;
2110
2211
  ha_rows end_write_records;
2111
2212
  uint  field_count,sum_func_count,func_count;
2112
 
  uint32_t  hidden_field_count;
 
2213
  uint  hidden_field_count;
2113
2214
  uint  group_parts,group_length,group_null_parts;
2114
2215
  uint  quick_group;
2115
2216
  bool  using_indirect_summary_function;
2116
2217
  /* If >0 convert all blob fields to varchar(convert_blob_length) */
2117
 
  uint32_t  convert_blob_length; 
 
2218
  uint  convert_blob_length; 
2118
2219
  const CHARSET_INFO *table_charset; 
2119
2220
  bool schema_table;
2120
2221
  /*
2157
2258
{
2158
2259
  TMP_TABLE_PARAM tmp_table_param;
2159
2260
public:
2160
 
  Table *table;
 
2261
  TABLE *table;
2161
2262
 
2162
2263
  select_union() :table(0) {}
2163
2264
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2224
2325
  Field *field;                         /* Field to sort */
2225
2326
  Item  *item;                          /* Item if not sorting fields */
2226
2327
  uint   length;                        /* Length of sort field */
2227
 
  uint32_t   suffix_length;                 /* Length suffix (0-4) */
 
2328
  uint   suffix_length;                 /* Length suffix (0-4) */
2228
2329
  Item_result result_type;              /* Type of item */
2229
2330
  bool reverse;                         /* if descending sort */
2230
2331
  bool need_strxnfrm;                   /* If we have to use strxnfrm() */
2232
2333
 
2233
2334
 
2234
2335
typedef struct st_sort_buffer {
2235
 
  uint32_t index;                                       /* 0 or 1 */
2236
 
  uint32_t sort_orders;
2237
 
  uint32_t change_pos;                          /* If sort-fields changed */
 
2336
  uint index;                                   /* 0 or 1 */
 
2337
  uint sort_orders;
 
2338
  uint change_pos;                              /* If sort-fields changed */
2238
2339
  char **buff;
2239
2340
  SORT_FIELD *sortorder;
2240
2341
} SORT_BUFFER;
2296
2397
 
2297
2398
  double val_real(bool *null_value);
2298
2399
  int64_t val_int(bool *null_value) const;
2299
 
  String *val_str(bool *null_value, String *str, uint32_t decimals);
 
2400
  String *val_str(bool *null_value, String *str, uint decimals);
2300
2401
  my_decimal *val_decimal(bool *null_value, my_decimal *result);
2301
2402
  DTCollation collation;
2302
2403
};
2316
2417
  uint64_t max_in_memory_size;
2317
2418
  IO_CACHE file;
2318
2419
  TREE tree;
2319
 
  unsigned char *record_pointers;
 
2420
  uchar *record_pointers;
2320
2421
  bool flush();
2321
 
  uint32_t size;
 
2422
  uint size;
2322
2423
 
2323
2424
public:
2324
2425
  ulong elements;
2325
2426
  Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2326
 
         uint32_t size_arg, uint64_t max_in_memory_size_arg);
 
2427
         uint size_arg, uint64_t max_in_memory_size_arg);
2327
2428
  ~Unique();
2328
2429
  ulong elements_in_tree() { return tree.elements_in_tree; }
2329
2430
  inline bool unique_add(void *ptr)
2333
2434
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2334
2435
  }
2335
2436
 
2336
 
  bool get(Table *table);
2337
 
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, 
 
2437
  bool get(TABLE *table);
 
2438
  static double get_use_cost(uint *buffer, uint nkeys, uint key_size, 
2338
2439
                             uint64_t max_in_memory_size);
2339
 
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, 
 
2440
  inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size, 
2340
2441
                                            uint64_t max_in_memory_size)
2341
2442
  {
2342
2443
    register uint64_t max_elems_in_tree=
2347
2448
  void reset();
2348
2449
  bool walk(tree_walk_action action, void *walk_action_arg);
2349
2450
 
2350
 
  friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
2351
 
  friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
 
2451
  friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
 
2452
  friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2352
2453
};
2353
2454
 
2354
2455
 
2355
2456
class multi_delete :public select_result_interceptor
2356
2457
{
2357
 
  TableList *delete_tables, *table_being_deleted;
 
2458
  TABLE_LIST *delete_tables, *table_being_deleted;
2358
2459
  Unique **tempfiles;
2359
2460
  ha_rows deleted, found;
2360
 
  uint32_t num_of_tables;
 
2461
  uint num_of_tables;
2361
2462
  int error;
2362
2463
  bool do_delete;
2363
2464
  /* True if at least one table we delete from is transactional */
2372
2473
  bool error_handled;
2373
2474
 
2374
2475
public:
2375
 
  multi_delete(TableList *dt, uint32_t num_of_tables);
 
2476
  multi_delete(TABLE_LIST *dt, uint num_of_tables);
2376
2477
  ~multi_delete();
2377
2478
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2378
2479
  bool send_data(List<Item> &items);
2379
2480
  bool initialize_tables (JOIN *join);
2380
 
  void send_error(uint32_t errcode,const char *err);
 
2481
  void send_error(uint errcode,const char *err);
2381
2482
  int  do_deletes();
2382
2483
  bool send_eof();
2383
2484
  virtual void abort();
2386
2487
 
2387
2488
class multi_update :public select_result_interceptor
2388
2489
{
2389
 
  TableList *all_tables; /* query/update command tables */
2390
 
  TableList *leaves;     /* list of leves of join table tree */
2391
 
  TableList *update_tables, *table_being_updated;
2392
 
  Table **tmp_tables, *main_table, *table_to_update;
 
2490
  TABLE_LIST *all_tables; /* query/update command tables */
 
2491
  TABLE_LIST *leaves;     /* list of leves of join table tree */
 
2492
  TABLE_LIST *update_tables, *table_being_updated;
 
2493
  TABLE **tmp_tables, *main_table, *table_to_update;
2393
2494
  TMP_TABLE_PARAM *tmp_table_param;
2394
2495
  ha_rows updated, found;
2395
2496
  List <Item> *fields, *values;
2396
2497
  List <Item> **fields_for_table, **values_for_table;
2397
 
  uint32_t table_count;
 
2498
  uint table_count;
2398
2499
  /*
2399
2500
   List of tables referenced in the CHECK OPTION condition of
2400
2501
   the updated view excluding the updated table. 
2401
2502
  */
2402
 
  List <Table> unupdated_check_opt_tables;
 
2503
  List <TABLE> unupdated_check_opt_tables;
2403
2504
  Copy_field *copy_field;
2404
2505
  enum enum_duplicates handle_duplicates;
2405
2506
  bool do_update, trans_safe;
2413
2514
  bool error_handled;
2414
2515
 
2415
2516
public:
2416
 
  multi_update(TableList *ut, TableList *leaves_list,
 
2517
  multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2417
2518
               List<Item> *fields, List<Item> *values,
2418
2519
               enum_duplicates handle_duplicates, bool ignore);
2419
2520
  ~multi_update();
2420
2521
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2421
2522
  bool send_data(List<Item> &items);
2422
2523
  bool initialize_tables (JOIN *join);
2423
 
  void send_error(uint32_t errcode,const char *err);
 
2524
  void send_error(uint errcode,const char *err);
2424
2525
  int  do_updates();
2425
2526
  bool send_eof();
2426
2527
  virtual void abort();
2430
2531
public:
2431
2532
  LEX_STRING s;
2432
2533
  bool local;
2433
 
  uint32_t offset;
 
2534
  uint offset;
2434
2535
  enum_field_types type;
2435
 
  my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
 
2536
  my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2436
2537
    :s(j), local(i), offset(o), type(t)
2437
2538
  {}
2438
2539
  ~my_var() {}
2466
2567
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2467
2568
                        STATUS_VAR *dec_var);
2468
2569
 
2469
 
#endif /* DRIZZLE_SERVER */
 
2570
#endif /* MYSQL_SERVER */