~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_class.h

  • Committer: Jay Pipes
  • Date: 2008-07-21 17:52:33 UTC
  • mto: (201.2.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: jay@mysql.com-20080721175233-mtyz298j8xl3v63y
cleanup of FAQ file

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 */
22
 
#include <drizzled/global.h>
 
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
 
23
#include <mysql/plugin_audit.h>
23
24
#include "log.h"
24
25
#include "rpl_tblmap.h"
25
26
 
52
53
 
53
54
#define TC_HEURISTIC_RECOVER_COMMIT   1
54
55
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
55
 
extern uint32_t tc_heuristic_recover;
 
56
extern uint tc_heuristic_recover;
56
57
 
57
58
typedef struct st_user_var_events
58
59
{
60
61
  char *value;
61
62
  ulong length;
62
63
  Item_result type;
63
 
  uint32_t charset_number;
 
64
  uint charset_number;
64
65
} BINLOG_USER_VAR_EVENT;
65
66
 
66
67
#define RP_LOCK_LOG_IS_ALREADY_LOCKED 1
98
99
class Key_part_spec :public Sql_alloc {
99
100
public:
100
101
  LEX_STRING field_name;
101
 
  uint32_t length;
102
 
  Key_part_spec(const LEX_STRING &name, uint32_t len)
 
102
  uint length;
 
103
  Key_part_spec(const LEX_STRING &name, uint len)
103
104
    : field_name(name), length(len)
104
105
  {}
105
 
  Key_part_spec(const char *name, const size_t name_len, uint32_t len)
 
106
  Key_part_spec(const char *name, const size_t name_len, uint len)
106
107
    : length(len)
107
108
  { field_name.str= (char *)name; field_name.length= name_len; }
108
109
  bool operator==(const Key_part_spec& other) const;
198
199
 
199
200
  Table_ident *ref_table;
200
201
  List<Key_part_spec> ref_columns;
201
 
  uint32_t delete_opt, update_opt, match_opt;
 
202
  uint delete_opt, update_opt, match_opt;
202
203
  Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
203
204
              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)
 
205
              uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
205
206
    :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
206
207
    ref_table(table), ref_columns(ref_cols),
207
208
    delete_opt(delete_opt_arg), update_opt(update_opt_arg),
214
215
  */
215
216
  virtual Key *clone(MEM_ROOT *mem_root) const
216
217
  { return new (mem_root) Foreign_key(*this, mem_root); }
217
 
  /* Used to validate foreign key options */
218
 
  bool validate(List<Create_field> &table_fields);
219
218
};
220
219
 
221
220
typedef struct st_mysql_lock
222
221
{
223
 
  Table **table;
224
 
  uint32_t table_count,lock_count;
 
222
  TABLE **table;
 
223
  uint table_count,lock_count;
225
224
  THR_LOCK_DATA **locks;
226
 
} DRIZZLE_LOCK;
 
225
} MYSQL_LOCK;
227
226
 
228
227
 
229
228
class LEX_COLUMN : public Sql_alloc
230
229
{
231
230
public:
232
231
  String column;
233
 
  uint32_t rights;
 
232
  uint rights;
234
233
  LEX_COLUMN (const String& x,const  uint& y ): column (x),rights (y) {}
235
234
};
236
235
 
 
236
#include "sql_lex.h"                            /* Must be here */
 
237
 
237
238
class select_result;
238
239
class Time_zone;
239
240
 
255
256
  */ 
256
257
  ulong dynamic_variables_version;
257
258
  char* dynamic_variables_ptr;
258
 
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
259
 
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
 
259
  uint dynamic_variables_head;  /* largest valid variable offset */
 
260
  uint dynamic_variables_size;  /* how many bytes are in use */
260
261
  
261
262
  uint64_t myisam_max_extra_sort_file_size;
262
263
  uint64_t myisam_max_sort_file_size;
337
338
  plugin_ref table_plugin;
338
339
 
339
340
  /* Only charset part of these variables is sensible */
340
 
  const CHARSET_INFO  *character_set_filesystem;
341
 
  const CHARSET_INFO  *character_set_client;
342
 
  const CHARSET_INFO  *character_set_results;
 
341
  CHARSET_INFO  *character_set_filesystem;
 
342
  CHARSET_INFO  *character_set_client;
 
343
  CHARSET_INFO  *character_set_results;
343
344
 
344
345
  /* Both charset and collation parts of these variables are important */
345
 
  const CHARSET_INFO    *collation_server;
346
 
  const CHARSET_INFO    *collation_database;
347
 
  const CHARSET_INFO  *collation_connection;
 
346
  CHARSET_INFO  *collation_server;
 
347
  CHARSET_INFO  *collation_database;
 
348
  CHARSET_INFO  *collation_connection;
348
349
 
349
350
  /* Locale Support */
350
351
  MY_LOCALE *lc_time_names;
351
352
 
352
353
  Time_zone *time_zone;
353
354
 
354
 
  /* DATE, DATETIME and DRIZZLE_TIME formats */
 
355
  /* DATE, DATETIME and MYSQL_TIME formats */
355
356
  DATE_TIME_FORMAT *date_format;
356
357
  DATE_TIME_FORMAT *datetime_format;
357
358
  DATE_TIME_FORMAT *time_format;
359
360
 
360
361
};
361
362
 
362
 
#include "sql_lex.h"  /* only for SQLCOM_END */
363
363
 
364
364
/* per thread status variables */
365
365
 
444
444
 
445
445
void mark_transaction_to_rollback(THD *thd, bool all);
446
446
 
447
 
#ifdef DRIZZLE_SERVER
 
447
#ifdef MYSQL_SERVER
 
448
 
 
449
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
448
450
 
449
451
class Query_arena
450
452
{
455
457
  */
456
458
  Item *free_list;
457
459
  MEM_ROOT *mem_root;                   // Pointer to current memroot
458
 
 
459
 
  Query_arena(MEM_ROOT *mem_root_arg) :
460
 
    free_list(0), mem_root(mem_root_arg)
461
 
  { }
 
460
  bool is_backup_arena; /* True if this arena is used for backup. */
 
461
 
 
462
  /*
 
463
    The states relfects three diffrent life cycles for three
 
464
    different types of statements:
 
465
    Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
 
466
    Stored procedure:   INITIALIZED_FOR_SP -> EXECUTED.
 
467
    Other statements:   CONVENTIONAL_EXECUTION never changes.
 
468
  */
 
469
  enum enum_state
 
470
  {
 
471
    INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2,
 
472
    CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
 
473
  };
 
474
 
 
475
  enum_state state;
 
476
 
 
477
  /* We build without RTTI, so dynamic_cast can't be used. */
 
478
  enum Type
 
479
  {
 
480
    STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE
 
481
  };
 
482
 
 
483
  Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
 
484
    free_list(0), mem_root(mem_root_arg), state(state_arg)
 
485
  { INIT_ARENA_DBUG_INFO; }
462
486
  /*
463
487
    This constructor is used only when Query_arena is created as
464
488
    backup storage for another instance of Query_arena.
465
489
  */
466
 
  Query_arena() { }
 
490
  Query_arena() { INIT_ARENA_DBUG_INFO; }
467
491
 
468
492
  virtual ~Query_arena() {};
469
493
 
 
494
  inline bool is_conventional() const
 
495
  { assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
 
496
 
470
497
  inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
471
498
  inline void* calloc(size_t size)
472
499
  {
473
500
    void *ptr;
474
501
    if ((ptr=alloc_root(mem_root,size)))
475
 
      memset(ptr, 0, size);
 
502
      bzero(ptr, size);
476
503
    return ptr;
477
504
  }
478
505
  inline char *strdup(const char *str)
481
508
  { return strmake_root(mem_root,str,size); }
482
509
  inline void *memdup(const void *str, size_t size)
483
510
  { return memdup_root(mem_root,str,size); }
484
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
 
511
  inline void *memdup_w_gap(const void *str, size_t size, uint gap)
485
512
  {
486
513
    void *ptr;
487
514
    if ((ptr= alloc_root(mem_root,size+gap)))
489
516
    return ptr;
490
517
  }
491
518
 
 
519
  void set_query_arena(Query_arena *set);
 
520
 
492
521
  void free_items();
 
522
  /* Close the active state associated with execution of this statement */
 
523
  virtual void cleanup_stmt();
493
524
};
494
525
 
495
526
 
530
561
  */
531
562
  enum enum_mark_columns mark_used_columns;
532
563
 
 
564
  LEX_STRING name; /* name for named prepared statements */
533
565
  LEX *lex;                                     // parse tree descriptor
534
566
  /*
535
567
    Points to the query associated with this statement. It's const, but
554
586
    STATUS.
555
587
  */
556
588
  char *query;
557
 
  uint32_t query_length;                          // current query length
 
589
  uint32 query_length;                          // current query length
558
590
 
559
591
  /**
560
592
    Name of the current (default) database.
570
602
  */
571
603
 
572
604
  char *db;
573
 
  uint32_t db_length;
 
605
  uint db_length;
574
606
 
575
607
public:
576
608
 
577
609
  /* This constructor is called for backup statements */
578
610
  Statement() {}
579
611
 
580
 
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
 
612
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
 
613
            enum enum_state state_arg, ulong id_arg);
581
614
  ~Statement() {}
 
615
 
 
616
  /* Assign execution context (note: not all members) of given stmt to self */
 
617
  void set_statement(Statement *stmt);
 
618
  void set_n_backup_statement(Statement *stmt, Statement *backup);
 
619
  void restore_backup_statement(Statement *stmt, Statement *backup);
582
620
};
583
621
 
584
622
struct st_savepoint {
585
623
  struct st_savepoint *prev;
586
624
  char                *name;
587
 
  uint32_t                 length;
 
625
  uint                 length;
588
626
  Ha_trx_info         *ha_list;
589
627
};
590
628
 
622
660
    priv_user - The user privilege we are using. May be "" for anonymous user.
623
661
    ip - client IP
624
662
  */
625
 
  char *user; 
626
 
  char *ip;
 
663
  char   *host, *user, *priv_user, *ip;
 
664
  /* The host privilege we are using */
 
665
  char   priv_host[MAX_HOSTNAME];
 
666
  /* points to host if host is available, otherwise points to ip */
 
667
  const char *host_or_ip;
 
668
  ulong db_access;                     /* Privileges for current db */
627
669
 
628
670
  void init();
629
671
  void destroy();
630
672
  void skip_grants();
631
673
  inline char *priv_host_name()
632
674
  {
633
 
    return (ip ? ip : (char *)"%");
 
675
    return (*priv_host ? priv_host : (char *)"%");
634
676
  }
635
677
};
636
678
 
659
701
    List of regular tables in use by this thread. Contains temporary and
660
702
    base tables that were opened with @see open_tables().
661
703
  */
662
 
  Table *open_tables;
 
704
  TABLE *open_tables;
663
705
  /**
664
706
    List of temporary tables used by this thread. Contains user-level
665
707
    temporary tables, created with CREATE TEMPORARY TABLE, and
667
709
    or for an intermediate table used in ALTER.
668
710
    XXX Why are internal temporary tables added to this list?
669
711
  */
670
 
  Table *temporary_tables;
 
712
  TABLE *temporary_tables;
671
713
  /**
672
714
    List of tables that were opened with HANDLER OPEN and are
673
715
    still in use by this thread.
674
716
  */
675
 
  Table *handler_tables;
676
 
  Table *derived_tables;
 
717
  TABLE *handler_tables;
 
718
  TABLE *derived_tables;
677
719
  /*
678
720
    During a MySQL session, one can lock tables in two modes: automatic
679
721
    or manual. In automatic mode all necessary tables are locked just before
687
729
    the 'LOCK_TABLES' chapter of the MySQL manual.
688
730
    See also lock_tables() for details.
689
731
  */
690
 
  DRIZZLE_LOCK *lock;
 
732
  MYSQL_LOCK *lock;
691
733
  /*
692
734
    Tables that were locked with explicit or implicit LOCK TABLES.
693
735
    (Implicit LOCK TABLES happens when we are prelocking tables for
694
736
     execution of statement which uses stored routines. See description
695
737
     THD::prelocked_mode for more info.)
696
738
  */
697
 
  DRIZZLE_LOCK *locked_tables;
 
739
  MYSQL_LOCK *locked_tables;
698
740
 
699
741
  /*
700
742
    CREATE-SELECT keeps an extra lock for the table being
701
743
    created. This field is used to keep the extra lock available for
702
744
    lower level routines, which would otherwise miss that lock.
703
745
   */
704
 
  DRIZZLE_LOCK *extra_lock;
 
746
  MYSQL_LOCK *extra_lock;
705
747
 
706
748
  ulong version;
707
 
  uint32_t current_tablenr;
 
749
  uint current_tablenr;
708
750
 
709
751
  enum enum_flags {
710
752
    BACKUPS_AVAIL = (1U << 0)     /* There are backups available */
713
755
  /*
714
756
    Flags with information about the open tables state.
715
757
  */
716
 
  uint32_t state_flags;
 
758
  uint state_flags;
717
759
 
718
760
  /*
719
761
    This constructor serves for creation of Open_tables_state instances
736
778
  }
737
779
};
738
780
 
 
781
/**
 
782
  @class Sub_statement_state
 
783
  @brief Used to save context when executing a function or trigger
 
784
*/
 
785
 
 
786
/* Defines used for Sub_statement_state::in_sub_stmt */
 
787
 
 
788
#define SUB_STMT_TRIGGER 1
 
789
#define SUB_STMT_FUNCTION 2
 
790
 
 
791
 
 
792
class Sub_statement_state
 
793
{
 
794
public:
 
795
  uint64_t options;
 
796
  uint64_t first_successful_insert_id_in_prev_stmt;
 
797
  uint64_t first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
 
798
  Discrete_interval auto_inc_interval_for_cur_row;
 
799
  Discrete_intervals_list auto_inc_intervals_forced;
 
800
  uint64_t limit_found_rows;
 
801
  ha_rows    cuted_fields, sent_row_count, examined_row_count;
 
802
  ulong client_capabilities;
 
803
  uint in_sub_stmt;
 
804
  bool enable_slow_log;
 
805
  bool last_insert_id_used;
 
806
  SAVEPOINT *savepoints;
 
807
};
 
808
 
739
809
 
740
810
/* Flags for the THD::system_thread variable */
741
811
enum enum_thread_type
783
853
    @param thd the calling thread
784
854
    @return true if the error is handled
785
855
  */
786
 
  virtual bool handle_error(uint32_t sql_errno,
 
856
  virtual bool handle_error(uint sql_errno,
787
857
                            const char *message,
788
 
                            DRIZZLE_ERROR::enum_warning_level level,
 
858
                            MYSQL_ERROR::enum_warning_level level,
789
859
                            THD *thd) = 0;
790
860
};
791
861
 
822
892
                     uint64_t last_insert_id_arg,
823
893
                     const char *message);
824
894
  void set_eof_status(THD *thd);
825
 
  void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
 
895
  void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
826
896
 
827
897
  void disable_status();
828
898
 
838
908
  const char *message() const
839
909
  { assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
840
910
 
841
 
  uint32_t sql_errno() const
 
911
  uint sql_errno() const
842
912
  { assert(m_status == DA_ERROR); return m_sql_errno; }
843
913
 
844
 
  uint32_t server_status() const
 
914
  uint server_status() const
845
915
  {
846
916
    assert(m_status == DA_OK || m_status == DA_EOF);
847
917
    return m_server_status;
853
923
  uint64_t last_insert_id() const
854
924
  { assert(m_status == DA_OK); return m_last_insert_id; }
855
925
 
856
 
  uint32_t total_warn_count() const
 
926
  uint total_warn_count() const
857
927
  {
858
928
    assert(m_status == DA_OK || m_status == DA_EOF);
859
929
    return m_total_warn_count;
863
933
 
864
934
private:
865
935
  /** Message buffer. Can be used by OK or ERROR status. */
866
 
  char m_message[DRIZZLE_ERRMSG_SIZE];
 
936
  char m_message[MYSQL_ERRMSG_SIZE];
867
937
  /**
868
938
    SQL error number. One of ER_ codes from share/errmsg.txt.
869
939
    Set by set_error_status.
870
940
  */
871
 
  uint32_t m_sql_errno;
 
941
  uint m_sql_errno;
872
942
 
873
943
  /**
874
944
    Copied from thd->server_status when the diagnostics area is assigned.
878
948
    thd->server_status&= ~...
879
949
    Assigned by OK, EOF or ERROR.
880
950
  */
881
 
  uint32_t m_server_status;
 
951
  uint m_server_status;
882
952
  /**
883
953
    The number of rows affected by the last statement. This is
884
954
    semantically close to thd->row_count_func, but has a different
1006
1076
    Set it using the  thd_proc_info(THD *thread, const char *message)
1007
1077
    macro/function.
1008
1078
  */
1009
 
  void        set_proc_info(const char *info) { proc_info= info; }
1010
 
  const char* get_proc_info() const { return proc_info; }
 
1079
#define THD_SET_PROC_INFO(thd, info) \
 
1080
    (thd)->proc_info= (info)
 
1081
 
 
1082
  inline const char* get_proc_info() { return proc_info;}
 
1083
 
 
1084
  /* left public for the the storage engines, please avoid direct use */
 
1085
  const char *proc_info;
1011
1086
 
1012
1087
  /*
1013
1088
    Used in error messages to tell user in what part of MySQL we found an
1026
1101
    points to a lock object if the lock is present. See item_func.cc and
1027
1102
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK. 
1028
1103
  */
1029
 
  uint32_t dbug_sentry; // watch out for memory corruption
 
1104
  uint dbug_sentry; // watch out for memory corruption
1030
1105
  struct st_my_thread_var *mysys_var;
1031
1106
  /*
1032
1107
    Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1033
1108
    first byte of the packet in do_command()
1034
1109
  */
1035
1110
  enum enum_server_command command;
1036
 
  uint32_t     server_id;
1037
 
  uint32_t     file_id;                 // for LOAD DATA INFILE
 
1111
  uint32     server_id;
 
1112
  uint32     file_id;                   // for LOAD DATA INFILE
1038
1113
  /* remote (peer) port */
1039
 
  uint16_t peer_port;
 
1114
  uint16 peer_port;
1040
1115
  time_t     start_time, user_time;
1041
1116
  uint64_t  connect_utime, thr_create_utime; // track down slow pthread_create
1042
1117
  uint64_t  start_utime, utime_after_lock;
1043
1118
  
1044
1119
  thr_lock_type update_lock_default;
1045
1120
 
 
1121
  /* <> 0 if we are inside of trigger or stored function. */
 
1122
  uint in_sub_stmt;
 
1123
 
1046
1124
  /* container for handler's private per-connection data */
1047
1125
  Ha_data ha_data[MAX_HA];
1048
1126
 
1049
1127
  /* Place to store various things */
1050
1128
  void *thd_marker;
 
1129
#ifndef MYSQL_CLIENT
1051
1130
  int binlog_setup_trx_data();
1052
1131
 
1053
1132
  /*
1055
1134
  */
1056
1135
  void binlog_start_trans_and_stmt();
1057
1136
  void binlog_set_stmt_begin();
1058
 
  int binlog_write_table_map(Table *table, bool is_transactional);
1059
 
  int binlog_write_row(Table* table, bool is_transactional,
1060
 
                       const unsigned char *new_data);
1061
 
  int binlog_delete_row(Table* table, bool is_transactional,
1062
 
                        const unsigned char *old_data);
1063
 
  int binlog_update_row(Table* table, bool is_transactional,
1064
 
                        const unsigned char *old_data, const unsigned char *new_data);
 
1137
  int binlog_write_table_map(TABLE *table, bool is_transactional);
 
1138
  int binlog_write_row(TABLE* table, bool is_transactional,
 
1139
                       const uchar *new_data);
 
1140
  int binlog_delete_row(TABLE* table, bool is_transactional,
 
1141
                        const uchar *old_data);
 
1142
  int binlog_update_row(TABLE* table, bool is_transactional,
 
1143
                        const uchar *old_data, const uchar *new_data);
1065
1144
 
1066
 
  void set_server_id(uint32_t sid) { server_id = sid; }
 
1145
  void set_server_id(uint32 sid) { server_id = sid; }
1067
1146
 
1068
1147
  /*
1069
1148
    Member functions to handle pending event for row-level logging.
1070
1149
  */
1071
1150
  template <class RowsEventT> Rows_log_event*
1072
 
    binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
1151
    binlog_prepare_pending_rows_event(TABLE* table, uint32 serv_id,
1073
1152
                                      size_t needed,
1074
1153
                                      bool is_transactional,
1075
1154
                                      RowsEventT* hint);
1078
1157
  int binlog_flush_pending_rows_event(bool stmt_end);
1079
1158
 
1080
1159
private:
1081
 
  uint32_t binlog_table_maps; // Number of table maps currently in the binlog
 
1160
  uint binlog_table_maps; // Number of table maps currently in the binlog
1082
1161
 
1083
1162
  enum enum_binlog_flag {
1084
1163
    BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1089
1168
     Flags with per-thread information regarding the status of the
1090
1169
     binary log.
1091
1170
   */
1092
 
  uint32_t binlog_flags;
 
1171
  uint32 binlog_flags;
1093
1172
public:
1094
 
  uint32_t get_binlog_table_maps() const {
 
1173
  uint get_binlog_table_maps() const {
1095
1174
    return binlog_table_maps;
1096
1175
  }
1097
1176
  void clear_binlog_table_maps() {
1098
1177
    binlog_table_maps= 0;
1099
1178
  }
 
1179
#endif /* MYSQL_CLIENT */
1100
1180
 
1101
1181
public:
1102
1182
 
1113
1193
       List contain only transactional tables, that not invalidated in query
1114
1194
       cache (instead of full list of changed in transaction tables).
1115
1195
    */
1116
 
    CHANGED_TableList* changed_tables;
 
1196
    CHANGED_TABLE_LIST* changed_tables;
1117
1197
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
1118
1198
    void cleanup()
1119
1199
    {
1123
1203
    }
1124
1204
    st_transactions()
1125
1205
    {
1126
 
      memset(this, 0, sizeof(*this));
 
1206
      bzero((char*)this, sizeof(*this));
1127
1207
      xid_state.xid.null();
1128
1208
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
1129
1209
    }
1130
1210
  } transaction;
1131
1211
  Field      *dup_field;
1132
1212
  sigset_t signals;
 
1213
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1214
  Vio* active_vio;
 
1215
#endif
1133
1216
  /*
1134
1217
    This is to track items changed during execution of a prepared
1135
1218
    statement/stored procedure. It's created by
1139
1222
  */
1140
1223
  Item_change_list change_list;
1141
1224
 
 
1225
  /*
 
1226
    A permanent memory area of the statement. For conventional
 
1227
    execution, the parsed tree and execution runtime reside in the same
 
1228
    memory root. In this case stmt_arena points to THD. In case of
 
1229
    a prepared statement or a stored procedure statement, thd->mem_root
 
1230
    conventionally points to runtime memory, and thd->stmt_arena
 
1231
    points to the memory of the PS/SP, where the parsed tree of the
 
1232
    statement resides. Whenever you need to perform a permanent
 
1233
    transformation of a parsed tree, you should allocate new memory in
 
1234
    stmt_arena, to allow correct re-execution of PS/SP.
 
1235
    Note: in the parser, stmt_arena == thd, even for PS/SP.
 
1236
  */
 
1237
  Query_arena *stmt_arena;
1142
1238
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
1143
1239
  bool arg_of_last_insert_id_function;
1144
1240
  /*
1297
1393
  */
1298
1394
  table_map  used_tables;
1299
1395
  USER_CONN *user_connect;
1300
 
  const CHARSET_INFO *db_charset;
 
1396
  CHARSET_INFO *db_charset;
1301
1397
  /*
1302
1398
    FIXME: this, and some other variables like 'count_cuted_fields'
1303
1399
    maybe should be statement/cursor local, that is, moved to Statement
1304
1400
    class. With current implementation warnings produced in each prepared
1305
1401
    statement/cursor settle here.
1306
1402
  */
1307
 
  List       <DRIZZLE_ERROR> warn_list;
1308
 
  uint       warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
 
1403
  List       <MYSQL_ERROR> warn_list;
 
1404
  uint       warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
1309
1405
  uint       total_warn_count;
1310
1406
  Diagnostics_area main_da;
1311
1407
 
1336
1432
  uint       tmp_table, global_read_lock;
1337
1433
  uint       server_status,open_options;
1338
1434
  enum enum_thread_type system_thread;
1339
 
  uint32_t       select_number;             //number of select (used for EXPLAIN)
 
1435
  uint       select_number;             //number of select (used for EXPLAIN)
1340
1436
  /* variables.transaction_isolation is reset to this after each commit */
1341
1437
  enum_tx_isolation session_tx_isolation;
1342
1438
  enum_check_fields count_cuted_fields;
1400
1496
    it returned an error on master, and this is OK on the slave.
1401
1497
  */
1402
1498
  bool       is_slave_error;
1403
 
  bool       cleanup_done;
 
1499
  bool       bootstrap, cleanup_done;
1404
1500
  
1405
1501
  /**  is set if some thread specific value(s) used in a statement. */
1406
1502
  bool       thread_specific_used;
1407
1503
  bool       charset_is_system_charset, charset_is_collation_connection;
1408
1504
  bool       charset_is_character_set_filesystem;
 
1505
  bool       enable_slow_log;   /* enable slow log for current statement */
1409
1506
  bool       abort_on_warning;
1410
1507
  bool       got_warning;       /* Set on call to push_warning() */
1411
1508
  bool       no_warnings_for_error; /* no warnings on call to my_error() */
1482
1579
  void cleanup(void);
1483
1580
  void cleanup_after_query();
1484
1581
  bool store_globals();
 
1582
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1583
  inline void set_active_vio(Vio* vio)
 
1584
  {
 
1585
    pthread_mutex_lock(&LOCK_delete);
 
1586
    active_vio = vio;
 
1587
    pthread_mutex_unlock(&LOCK_delete);
 
1588
  }
 
1589
  inline void clear_active_vio()
 
1590
  {
 
1591
    pthread_mutex_lock(&LOCK_delete);
 
1592
    active_vio = 0;
 
1593
    pthread_mutex_unlock(&LOCK_delete);
 
1594
  }
 
1595
  void close_active_vio();
 
1596
#endif
1485
1597
  void awake(THD::killed_state state_to_set);
1486
1598
 
 
1599
#ifndef MYSQL_CLIENT
1487
1600
  enum enum_binlog_query_type {
1488
1601
    /*
1489
1602
      The query can be logged row-based or statement-based
1499
1612
      The query represents a change to a table in the "mysql"
1500
1613
      database and is currently mapped to ROW_QUERY_TYPE.
1501
1614
    */
1502
 
    DRIZZLE_QUERY_TYPE,
 
1615
    MYSQL_QUERY_TYPE,
1503
1616
    QUERY_TYPE_COUNT
1504
1617
  };
1505
1618
  
1507
1620
                   char const *query, ulong query_len,
1508
1621
                   bool is_trans, bool suppress_use,
1509
1622
                   THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
 
1623
#endif
1510
1624
 
1511
1625
  /*
1512
1626
    For enter_cond() / exit_cond() to work the mutex must be got before
1520
1634
    safe_mutex_assert_owner(mutex);
1521
1635
    mysys_var->current_mutex = mutex;
1522
1636
    mysys_var->current_cond = cond;
1523
 
    this->set_proc_info(msg);
 
1637
    thd_proc_info(this, msg);
1524
1638
    return old_msg;
1525
1639
  }
1526
1640
  inline void exit_cond(const char* old_msg)
1535
1649
    pthread_mutex_lock(&mysys_var->mutex);
1536
1650
    mysys_var->current_mutex = 0;
1537
1651
    mysys_var->current_cond = 0;
1538
 
    this->set_proc_info(old_msg);
 
1652
    thd_proc_info(this, old_msg);
1539
1653
    pthread_mutex_unlock(&mysys_var->mutex);
1540
1654
  }
1541
1655
  inline time_t query_start() { query_start_used=1; return start_time; }
1575
1689
  }
1576
1690
 
1577
1691
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1578
 
                              const char* str, uint32_t length,
 
1692
                              const char* str, uint length,
1579
1693
                              bool allocate_lex_string);
1580
1694
 
1581
 
  bool convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1582
 
                      const char *from, uint32_t from_length,
1583
 
                      const CHARSET_INFO * const from_cs);
1584
 
 
1585
 
  bool convert_string(String *s, const CHARSET_INFO * const from_cs, const CHARSET_INFO * const to_cs);
1586
 
 
1587
 
  void add_changed_table(Table *table);
 
1695
  bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
 
1696
                      const char *from, uint from_length,
 
1697
                      CHARSET_INFO *from_cs);
 
1698
 
 
1699
  bool convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs);
 
1700
 
 
1701
  void add_changed_table(TABLE *table);
1588
1702
  void add_changed_table(const char *key, long key_length);
1589
 
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
 
1703
  CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1590
1704
  int send_explain_fields(select_result *result);
1591
1705
  /**
1592
1706
    Clear the current error, if any.
1603
1717
    return;
1604
1718
  }
1605
1719
  inline bool vio_ok() const { return net.vio != 0; }
1606
 
 
 
1720
  /** Return false if connection to client is broken. */
 
1721
  bool vio_is_connected();
1607
1722
  /**
1608
1723
    Mark the current error as fatal. Warning: this does not
1609
1724
    set any error, it sets a property of the error, so must be
1628
1743
    To raise this flag, use my_error().
1629
1744
  */
1630
1745
  inline bool is_error() const { return main_da.is_error(); }
1631
 
  inline const CHARSET_INFO *charset() { return variables.character_set_client; }
 
1746
  inline CHARSET_INFO *charset() { return variables.character_set_client; }
1632
1747
  void update_charset();
1633
1748
 
1634
1749
  void change_item_tree(Item **place, Item *new_value)
1635
1750
  {
 
1751
    /* TODO: check for OOM condition here */
 
1752
    if (!stmt_arena->is_conventional())
 
1753
      nocheck_register_item_tree_change(place, *place, mem_root);
1636
1754
    *place= new_value;
1637
1755
  }
1638
1756
  void nocheck_register_item_tree_change(Item **place, Item *old_value,
1649
1767
    killed_state killed_val; /* to cache the volatile 'killed' */
1650
1768
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1651
1769
  }
1652
 
  void send_kill_message() const;
 
1770
  inline void send_kill_message() const
 
1771
  {
 
1772
    int err= killed_errno();
 
1773
    if (err)
 
1774
      my_message(err, ER(err), MYF(0));
 
1775
  }
1653
1776
  /* return true if we will abort query if we make a warning now */
1654
1777
  inline bool really_abort_on_warning()
1655
1778
  {
1658
1781
  void set_status_var_init();
1659
1782
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
1660
1783
  void restore_backup_open_tables_state(Open_tables_state *backup);
 
1784
  void restore_sub_statement_state(Sub_statement_state *backup);
 
1785
  void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
 
1786
  void restore_active_arena(Query_arena *set, Query_arena *backup);
1661
1787
 
1662
1788
  inline void set_current_stmt_binlog_row_based_if_mixed()
1663
1789
  {
1664
 
    if (variables.binlog_format == BINLOG_FORMAT_MIXED)
 
1790
    /*
 
1791
      If in a stored/function trigger, the caller should already have done the
 
1792
      change. We test in_sub_stmt to prevent introducing bugs where people
 
1793
      wouldn't ensure that, and would switch to row-based mode in the middle
 
1794
      of executing a stored function/trigger (which is too late, see also
 
1795
      reset_current_stmt_binlog_row_based()); this condition will make their
 
1796
      tests fail and so force them to propagate the
 
1797
      lex->binlog_row_based_if_mixed upwards to the caller.
 
1798
    */
 
1799
    if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
 
1800
        (in_sub_stmt == 0))
1665
1801
      current_stmt_binlog_row_based= true;
1666
1802
  }
1667
1803
  inline void set_current_stmt_binlog_row_based()
1680
1816
      CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1681
1817
      # and row-based does not store updates to temp tables
1682
1818
      # in the binlog.
 
1819
      INSERT INTO u SELECT * FROM t; # stmt-based
 
1820
      and then the INSERT will fail as data inserted into t was not logged.
 
1821
      So we continue with row-based until the temp table is dropped.
 
1822
      If we are in a stored function or trigger, we mustn't reset in the
 
1823
      middle of its execution (as the binary logging way of a stored function
 
1824
      or trigger is decided when it starts executing, depending for example on
 
1825
      the caller (for a stored function: if caller is SELECT or
 
1826
      INSERT/UPDATE/DELETE...).
1683
1827
 
1684
1828
      Don't reset binlog format for NDB binlog injector thread.
1685
1829
    */
1686
 
    if (temporary_tables == NULL)
 
1830
    if ((temporary_tables == NULL) && (in_sub_stmt == 0))
1687
1831
    {
1688
1832
      current_stmt_binlog_row_based= 
1689
1833
        test(variables.binlog_format == BINLOG_FORMAT_ROW);
1718
1862
      memcpy(db, new_db, new_db_len+1);
1719
1863
    else
1720
1864
    {
1721
 
      if (db)
1722
 
        free(db);
 
1865
      x_free(db);
1723
1866
      if (new_db)
1724
1867
        db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR));
1725
1868
      else
1750
1893
    allocate memory for a deep copy: current database may be freed after
1751
1894
    a statement is parsed but before it's executed.
1752
1895
  */
1753
 
  bool copy_db_to(char **p_db, size_t *p_db_length);
 
1896
  bool copy_db_to(char **p_db, size_t *p_db_length)
 
1897
  {
 
1898
    if (db == NULL)
 
1899
    {
 
1900
      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
 
1901
      return true;
 
1902
    }
 
1903
    *p_db= strmake(db, db_length);
 
1904
    *p_db_length= db_length;
 
1905
    return false;
 
1906
  }
1754
1907
  thd_scheduler scheduler;
1755
1908
 
1756
1909
public:
1766
1919
    @param level the error level
1767
1920
    @return true if the error is handled
1768
1921
  */
1769
 
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1770
 
                            DRIZZLE_ERROR::enum_warning_level level);
 
1922
  virtual bool handle_error(uint sql_errno, const char *message,
 
1923
                            MYSQL_ERROR::enum_warning_level level);
1771
1924
 
1772
1925
  /**
1773
1926
    Remove the error handler last pushed.
1775
1928
  void pop_internal_handler();
1776
1929
 
1777
1930
private:
1778
 
  const char *proc_info;
1779
 
 
1780
1931
  /** The current internal error handler for this thread, or NULL. */
1781
1932
  Internal_error_handler *m_internal_handler;
1782
1933
  /**
1838
1989
  bool opt_enclosed;
1839
1990
  bool dumpfile;
1840
1991
  ulong skip_lines;
1841
 
  const CHARSET_INFO *cs;
 
1992
  CHARSET_INFO *cs;
1842
1993
  sql_exchange(char *name, bool dumpfile_flag,
1843
1994
               enum_filetype filetype_arg= FILETYPE_CSV);
1844
1995
};
1858
2009
public:
1859
2010
  select_result();
1860
2011
  virtual ~select_result() {};
1861
 
  virtual int prepare(List<Item> &list __attribute__((unused)),
 
2012
  virtual int prepare(List<Item> &list __attribute__((__unused__)),
1862
2013
                      SELECT_LEX_UNIT *u)
1863
2014
  {
1864
2015
    unit= u;
1870
2021
    we need to know number of columns in the result set (if
1871
2022
    there is a result set) apart from sending columns metadata.
1872
2023
  */
1873
 
  virtual uint32_t field_count(List<Item> &fields) const
 
2024
  virtual uint field_count(List<Item> &fields) const
1874
2025
  { return fields.elements; }
1875
 
  virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
 
2026
  virtual bool send_fields(List<Item> &list, uint flags)=0;
1876
2027
  virtual bool send_data(List<Item> &items)=0;
1877
 
  virtual bool initialize_tables (JOIN  __attribute__((unused)) *join=0)
 
2028
  virtual bool initialize_tables (JOIN  __attribute__((__unused__)) *join=0)
1878
2029
  { return 0; }
1879
 
  virtual void send_error(uint32_t errcode,const char *err);
 
2030
  virtual void send_error(uint errcode,const char *err);
1880
2031
  virtual bool send_eof()=0;
1881
2032
  /**
1882
2033
    Check if this query returns a result set and therefore is allowed in
1907
2058
{
1908
2059
public:
1909
2060
  select_result_interceptor() {}              /* Remove gcc warning */
1910
 
  uint32_t field_count(List<Item> &fields __attribute__((unused))) const
 
2061
  uint field_count(List<Item> &fields __attribute__((__unused__))) const
1911
2062
  { return 0; }
1912
 
  bool send_fields(List<Item> &fields __attribute__((unused)),
1913
 
                   uint32_t flag __attribute__((unused))) { return false; }
 
2063
  bool send_fields(List<Item> &fields __attribute__((__unused__)),
 
2064
                   uint flag __attribute__((__unused__))) { return false; }
1914
2065
};
1915
2066
 
1916
2067
 
1923
2074
  bool is_result_set_started;
1924
2075
public:
1925
2076
  select_send() :is_result_set_started(false) {}
1926
 
  bool send_fields(List<Item> &list, uint32_t flags);
 
2077
  bool send_fields(List<Item> &list, uint flags);
1927
2078
  bool send_data(List<Item> &items);
1928
2079
  bool send_eof();
1929
2080
  virtual bool check_simple_select() const { return false; }
1944
2095
  select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1945
2096
  { path[0]=0; }
1946
2097
  ~select_to_file();
1947
 
  void send_error(uint32_t errcode,const char *err);
 
2098
  void send_error(uint errcode,const char *err);
1948
2099
  bool send_eof();
1949
2100
  void cleanup();
1950
2101
};
1960
2111
 
1961
2112
 
1962
2113
class select_export :public select_to_file {
1963
 
  uint32_t field_term_length;
 
2114
  uint field_term_length;
1964
2115
  int field_sep_char,escape_char,line_sep_char;
1965
2116
  int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1966
2117
  /*
2000
2151
 
2001
2152
class select_insert :public select_result_interceptor {
2002
2153
 public:
2003
 
  TableList *table_list;
2004
 
  Table *table;
 
2154
  TABLE_LIST *table_list;
 
2155
  TABLE *table;
2005
2156
  List<Item> *fields;
2006
2157
  uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2007
2158
  COPY_INFO info;
2008
2159
  bool insert_into_view;
2009
 
  select_insert(TableList *table_list_par,
2010
 
                Table *table_par, List<Item> *fields_par,
 
2160
  select_insert(TABLE_LIST *table_list_par,
 
2161
                TABLE *table_par, List<Item> *fields_par,
2011
2162
                List<Item> *update_fields, List<Item> *update_values,
2012
2163
                enum_duplicates duplic, bool ignore);
2013
2164
  ~select_insert();
2016
2167
  bool send_data(List<Item> &items);
2017
2168
  virtual void store_values(List<Item> &values);
2018
2169
  virtual bool can_rollback_data() { return 0; }
2019
 
  void send_error(uint32_t errcode,const char *err);
 
2170
  void send_error(uint errcode,const char *err);
2020
2171
  bool send_eof();
2021
2172
  void abort();
2022
2173
  /* not implemented: select_insert is never re-used in prepared statements */
2025
2176
 
2026
2177
 
2027
2178
class select_create: public select_insert {
2028
 
  order_st *group;
2029
 
  TableList *create_table;
 
2179
  ORDER *group;
 
2180
  TABLE_LIST *create_table;
2030
2181
  HA_CREATE_INFO *create_info;
2031
 
  TableList *select_tables;
 
2182
  TABLE_LIST *select_tables;
2032
2183
  Alter_info *alter_info;
2033
2184
  Field **field;
2034
2185
  /* lock data for tmp table */
2035
 
  DRIZZLE_LOCK *m_lock;
 
2186
  MYSQL_LOCK *m_lock;
2036
2187
  /* m_lock or thd->extra_lock */
2037
 
  DRIZZLE_LOCK **m_plock;
 
2188
  MYSQL_LOCK **m_plock;
2038
2189
public:
2039
 
  select_create (TableList *table_arg,
 
2190
  select_create (TABLE_LIST *table_arg,
2040
2191
                 HA_CREATE_INFO *create_info_par,
2041
2192
                 Alter_info *alter_info_arg,
2042
2193
                 List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2043
 
                 TableList *select_tables_arg)
 
2194
                 TABLE_LIST *select_tables_arg)
2044
2195
    :select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2045
2196
    create_table(table_arg),
2046
2197
    create_info(create_info_par),
2050
2201
    {}
2051
2202
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2052
2203
 
2053
 
  void binlog_show_create_table(Table **tables, uint32_t count);
 
2204
  void binlog_show_create_table(TABLE **tables, uint count);
2054
2205
  void store_values(List<Item> &values);
2055
 
  void send_error(uint32_t errcode,const char *err);
 
2206
  void send_error(uint errcode,const char *err);
2056
2207
  bool send_eof();
2057
2208
  void abort();
2058
2209
  virtual bool can_rollback_data() { return 1; }
2063
2214
  int prepare2(void) { return 0; }
2064
2215
};
2065
2216
 
2066
 
#include <storage/myisam/myisam.h>
 
2217
#include <myisam.h>
2067
2218
 
2068
2219
/* 
2069
2220
  Param to create temporary tables when doing SELECT:s 
2083
2234
  List<Item> save_copy_funcs;
2084
2235
  Copy_field *copy_field, *copy_field_end;
2085
2236
  Copy_field *save_copy_field, *save_copy_field_end;
2086
 
  unsigned char     *group_buff;
 
2237
  uchar     *group_buff;
2087
2238
  Item      **items_to_copy;                    /* Fields in tmp table */
2088
2239
  MI_COLUMNDEF *recinfo,*start_recinfo;
2089
2240
  KEY *keyinfo;
2090
2241
  ha_rows end_write_records;
2091
2242
  uint  field_count,sum_func_count,func_count;
2092
 
  uint32_t  hidden_field_count;
 
2243
  uint  hidden_field_count;
2093
2244
  uint  group_parts,group_length,group_null_parts;
2094
2245
  uint  quick_group;
2095
2246
  bool  using_indirect_summary_function;
2096
2247
  /* If >0 convert all blob fields to varchar(convert_blob_length) */
2097
 
  uint32_t  convert_blob_length; 
2098
 
  const CHARSET_INFO *table_charset; 
 
2248
  uint  convert_blob_length; 
 
2249
  CHARSET_INFO *table_charset; 
2099
2250
  bool schema_table;
2100
2251
  /*
2101
2252
    True if GROUP BY and its aggregate functions are already computed
2137
2288
{
2138
2289
  TMP_TABLE_PARAM tmp_table_param;
2139
2290
public:
2140
 
  Table *table;
 
2291
  TABLE *table;
2141
2292
 
2142
2293
  select_union() :table(0) {}
2143
2294
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2204
2355
  Field *field;                         /* Field to sort */
2205
2356
  Item  *item;                          /* Item if not sorting fields */
2206
2357
  uint   length;                        /* Length of sort field */
2207
 
  uint32_t   suffix_length;                 /* Length suffix (0-4) */
 
2358
  uint   suffix_length;                 /* Length suffix (0-4) */
2208
2359
  Item_result result_type;              /* Type of item */
2209
2360
  bool reverse;                         /* if descending sort */
2210
2361
  bool need_strxnfrm;                   /* If we have to use strxnfrm() */
2212
2363
 
2213
2364
 
2214
2365
typedef struct st_sort_buffer {
2215
 
  uint32_t index;                                       /* 0 or 1 */
2216
 
  uint32_t sort_orders;
2217
 
  uint32_t change_pos;                          /* If sort-fields changed */
 
2366
  uint index;                                   /* 0 or 1 */
 
2367
  uint sort_orders;
 
2368
  uint change_pos;                              /* If sort-fields changed */
2218
2369
  char **buff;
2219
2370
  SORT_FIELD *sortorder;
2220
2371
} SORT_BUFFER;
2274
2425
  Item_result type;
2275
2426
  bool unsigned_flag;
2276
2427
 
2277
 
  double val_real(bool *null_value);
2278
 
  int64_t val_int(bool *null_value) const;
2279
 
  String *val_str(bool *null_value, String *str, uint32_t decimals);
2280
 
  my_decimal *val_decimal(bool *null_value, my_decimal *result);
 
2428
  double val_real(my_bool *null_value);
 
2429
  int64_t val_int(my_bool *null_value) const;
 
2430
  String *val_str(my_bool *null_value, String *str, uint decimals);
 
2431
  my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
2281
2432
  DTCollation collation;
2282
2433
};
2283
2434
 
2296
2447
  uint64_t max_in_memory_size;
2297
2448
  IO_CACHE file;
2298
2449
  TREE tree;
2299
 
  unsigned char *record_pointers;
 
2450
  uchar *record_pointers;
2300
2451
  bool flush();
2301
 
  uint32_t size;
 
2452
  uint size;
2302
2453
 
2303
2454
public:
2304
2455
  ulong elements;
2305
2456
  Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2306
 
         uint32_t size_arg, uint64_t max_in_memory_size_arg);
 
2457
         uint size_arg, uint64_t max_in_memory_size_arg);
2307
2458
  ~Unique();
2308
2459
  ulong elements_in_tree() { return tree.elements_in_tree; }
2309
2460
  inline bool unique_add(void *ptr)
2313
2464
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2314
2465
  }
2315
2466
 
2316
 
  bool get(Table *table);
2317
 
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, 
 
2467
  bool get(TABLE *table);
 
2468
  static double get_use_cost(uint *buffer, uint nkeys, uint key_size, 
2318
2469
                             uint64_t max_in_memory_size);
2319
 
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, 
 
2470
  inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size, 
2320
2471
                                            uint64_t max_in_memory_size)
2321
2472
  {
2322
2473
    register uint64_t max_elems_in_tree=
2327
2478
  void reset();
2328
2479
  bool walk(tree_walk_action action, void *walk_action_arg);
2329
2480
 
2330
 
  friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
2331
 
  friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
 
2481
  friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
 
2482
  friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2332
2483
};
2333
2484
 
2334
2485
 
2335
2486
class multi_delete :public select_result_interceptor
2336
2487
{
2337
 
  TableList *delete_tables, *table_being_deleted;
 
2488
  TABLE_LIST *delete_tables, *table_being_deleted;
2338
2489
  Unique **tempfiles;
2339
2490
  ha_rows deleted, found;
2340
 
  uint32_t num_of_tables;
 
2491
  uint num_of_tables;
2341
2492
  int error;
2342
2493
  bool do_delete;
2343
2494
  /* True if at least one table we delete from is transactional */
2352
2503
  bool error_handled;
2353
2504
 
2354
2505
public:
2355
 
  multi_delete(TableList *dt, uint32_t num_of_tables);
 
2506
  multi_delete(TABLE_LIST *dt, uint num_of_tables);
2356
2507
  ~multi_delete();
2357
2508
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2358
2509
  bool send_data(List<Item> &items);
2359
2510
  bool initialize_tables (JOIN *join);
2360
 
  void send_error(uint32_t errcode,const char *err);
 
2511
  void send_error(uint errcode,const char *err);
2361
2512
  int  do_deletes();
2362
2513
  bool send_eof();
2363
2514
  virtual void abort();
2366
2517
 
2367
2518
class multi_update :public select_result_interceptor
2368
2519
{
2369
 
  TableList *all_tables; /* query/update command tables */
2370
 
  TableList *leaves;     /* list of leves of join table tree */
2371
 
  TableList *update_tables, *table_being_updated;
2372
 
  Table **tmp_tables, *main_table, *table_to_update;
 
2520
  TABLE_LIST *all_tables; /* query/update command tables */
 
2521
  TABLE_LIST *leaves;     /* list of leves of join table tree */
 
2522
  TABLE_LIST *update_tables, *table_being_updated;
 
2523
  TABLE **tmp_tables, *main_table, *table_to_update;
2373
2524
  TMP_TABLE_PARAM *tmp_table_param;
2374
2525
  ha_rows updated, found;
2375
2526
  List <Item> *fields, *values;
2376
2527
  List <Item> **fields_for_table, **values_for_table;
2377
 
  uint32_t table_count;
 
2528
  uint table_count;
2378
2529
  /*
2379
2530
   List of tables referenced in the CHECK OPTION condition of
2380
2531
   the updated view excluding the updated table. 
2381
2532
  */
2382
 
  List <Table> unupdated_check_opt_tables;
 
2533
  List <TABLE> unupdated_check_opt_tables;
2383
2534
  Copy_field *copy_field;
2384
2535
  enum enum_duplicates handle_duplicates;
2385
2536
  bool do_update, trans_safe;
2393
2544
  bool error_handled;
2394
2545
 
2395
2546
public:
2396
 
  multi_update(TableList *ut, TableList *leaves_list,
 
2547
  multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2397
2548
               List<Item> *fields, List<Item> *values,
2398
2549
               enum_duplicates handle_duplicates, bool ignore);
2399
2550
  ~multi_update();
2400
2551
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2401
2552
  bool send_data(List<Item> &items);
2402
2553
  bool initialize_tables (JOIN *join);
2403
 
  void send_error(uint32_t errcode,const char *err);
 
2554
  void send_error(uint errcode,const char *err);
2404
2555
  int  do_updates();
2405
2556
  bool send_eof();
2406
2557
  virtual void abort();
2410
2561
public:
2411
2562
  LEX_STRING s;
2412
2563
  bool local;
2413
 
  uint32_t offset;
 
2564
  uint offset;
2414
2565
  enum_field_types type;
2415
 
  my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
 
2566
  my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2416
2567
    :s(j), local(i), offset(o), type(t)
2417
2568
  {}
2418
2569
  ~my_var() {}
2446
2597
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2447
2598
                        STATUS_VAR *dec_var);
2448
2599
 
2449
 
#endif /* DRIZZLE_SERVER */
 
2600
#endif /* MYSQL_SERVER */