~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_class.h

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

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),
218
219
 
219
220
typedef struct st_mysql_lock
220
221
{
221
 
  Table **table;
222
 
  uint32_t table_count,lock_count;
 
222
  TABLE **table;
 
223
  uint table_count,lock_count;
223
224
  THR_LOCK_DATA **locks;
224
 
} DRIZZLE_LOCK;
 
225
} MYSQL_LOCK;
225
226
 
226
227
 
227
228
class LEX_COLUMN : public Sql_alloc
228
229
{
229
230
public:
230
231
  String column;
231
 
  uint32_t rights;
 
232
  uint rights;
232
233
  LEX_COLUMN (const String& x,const  uint& y ): column (x),rights (y) {}
233
234
};
234
235
 
 
236
#include "sql_lex.h"                            /* Must be here */
 
237
 
235
238
class select_result;
236
239
class Time_zone;
237
240
 
253
256
  */ 
254
257
  ulong dynamic_variables_version;
255
258
  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 */
 
259
  uint dynamic_variables_head;  /* largest valid variable offset */
 
260
  uint dynamic_variables_size;  /* how many bytes are in use */
258
261
  
259
262
  uint64_t myisam_max_extra_sort_file_size;
260
263
  uint64_t myisam_max_sort_file_size;
320
323
  */
321
324
  my_thread_id pseudo_thread_id;
322
325
 
323
 
  bool low_priority_updates;
324
 
  bool new_mode;
 
326
  my_bool low_priority_updates;
 
327
  my_bool new_mode;
325
328
  /* 
326
329
    compatibility option:
327
330
      - index usage hints (USE INDEX without a FOR clause) behave as in 5.0 
328
331
  */
329
332
  bool old_mode;
330
 
  bool engine_condition_pushdown;
331
 
  bool keep_files_on_create;
 
333
  my_bool engine_condition_pushdown;
 
334
  my_bool keep_files_on_create;
332
335
 
333
 
  bool old_alter_table;
 
336
  my_bool old_alter_table;
334
337
 
335
338
  plugin_ref table_plugin;
336
339
 
337
340
  /* Only charset part of these variables is sensible */
338
 
  const CHARSET_INFO  *character_set_filesystem;
339
 
  const CHARSET_INFO  *character_set_client;
340
 
  const CHARSET_INFO  *character_set_results;
 
341
  CHARSET_INFO  *character_set_filesystem;
 
342
  CHARSET_INFO  *character_set_client;
 
343
  CHARSET_INFO  *character_set_results;
341
344
 
342
345
  /* Both charset and collation parts of these variables are important */
343
 
  const CHARSET_INFO    *collation_server;
344
 
  const CHARSET_INFO    *collation_database;
345
 
  const CHARSET_INFO  *collation_connection;
 
346
  CHARSET_INFO  *collation_server;
 
347
  CHARSET_INFO  *collation_database;
 
348
  CHARSET_INFO  *collation_connection;
346
349
 
347
350
  /* Locale Support */
348
351
  MY_LOCALE *lc_time_names;
349
352
 
350
353
  Time_zone *time_zone;
351
354
 
352
 
  /* DATE, DATETIME and DRIZZLE_TIME formats */
 
355
  /* DATE, DATETIME and MYSQL_TIME formats */
353
356
  DATE_TIME_FORMAT *date_format;
354
357
  DATE_TIME_FORMAT *datetime_format;
355
358
  DATE_TIME_FORMAT *time_format;
356
 
  bool sysdate_is_now;
 
359
  my_bool sysdate_is_now;
357
360
 
358
361
};
359
362
 
360
 
#include "sql_lex.h"  /* only for SQLCOM_END */
361
363
 
362
364
/* per thread status variables */
363
365
 
442
444
 
443
445
void mark_transaction_to_rollback(THD *thd, bool all);
444
446
 
445
 
#ifdef DRIZZLE_SERVER
 
447
#ifdef MYSQL_SERVER
 
448
 
 
449
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
446
450
 
447
451
class Query_arena
448
452
{
453
457
  */
454
458
  Item *free_list;
455
459
  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
 
  { }
 
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; }
460
486
  /*
461
487
    This constructor is used only when Query_arena is created as
462
488
    backup storage for another instance of Query_arena.
463
489
  */
464
 
  Query_arena() { }
 
490
  Query_arena() { INIT_ARENA_DBUG_INFO; }
465
491
 
466
492
  virtual ~Query_arena() {};
467
493
 
 
494
  inline bool is_conventional() const
 
495
  { assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
 
496
 
468
497
  inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
469
498
  inline void* calloc(size_t size)
470
499
  {
471
500
    void *ptr;
472
501
    if ((ptr=alloc_root(mem_root,size)))
473
 
      memset(ptr, 0, size);
 
502
      bzero(ptr, size);
474
503
    return ptr;
475
504
  }
476
505
  inline char *strdup(const char *str)
479
508
  { return strmake_root(mem_root,str,size); }
480
509
  inline void *memdup(const void *str, size_t size)
481
510
  { return memdup_root(mem_root,str,size); }
482
 
  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)
483
512
  {
484
513
    void *ptr;
485
514
    if ((ptr= alloc_root(mem_root,size+gap)))
487
516
    return ptr;
488
517
  }
489
518
 
 
519
  void set_query_arena(Query_arena *set);
 
520
 
490
521
  void free_items();
 
522
  /* Close the active state associated with execution of this statement */
 
523
  virtual void cleanup_stmt();
491
524
};
492
525
 
493
526
 
528
561
  */
529
562
  enum enum_mark_columns mark_used_columns;
530
563
 
 
564
  LEX_STRING name; /* name for named prepared statements */
531
565
  LEX *lex;                                     // parse tree descriptor
532
566
  /*
533
567
    Points to the query associated with this statement. It's const, but
552
586
    STATUS.
553
587
  */
554
588
  char *query;
555
 
  uint32_t query_length;                          // current query length
 
589
  uint32 query_length;                          // current query length
556
590
 
557
591
  /**
558
592
    Name of the current (default) database.
568
602
  */
569
603
 
570
604
  char *db;
571
 
  uint32_t db_length;
 
605
  uint db_length;
572
606
 
573
607
public:
574
608
 
575
609
  /* This constructor is called for backup statements */
576
610
  Statement() {}
577
611
 
578
 
  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);
579
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);
580
620
};
581
621
 
582
622
struct st_savepoint {
583
623
  struct st_savepoint *prev;
584
624
  char                *name;
585
 
  uint32_t                 length;
 
625
  uint                 length;
586
626
  Ha_trx_info         *ha_list;
587
627
};
588
628
 
620
660
    priv_user - The user privilege we are using. May be "" for anonymous user.
621
661
    ip - client IP
622
662
  */
623
 
  char *user; 
624
 
  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 */
625
669
 
626
670
  void init();
627
671
  void destroy();
628
672
  void skip_grants();
629
673
  inline char *priv_host_name()
630
674
  {
631
 
    return (ip ? ip : (char *)"%");
 
675
    return (*priv_host ? priv_host : (char *)"%");
632
676
  }
633
677
};
634
678
 
657
701
    List of regular tables in use by this thread. Contains temporary and
658
702
    base tables that were opened with @see open_tables().
659
703
  */
660
 
  Table *open_tables;
 
704
  TABLE *open_tables;
661
705
  /**
662
706
    List of temporary tables used by this thread. Contains user-level
663
707
    temporary tables, created with CREATE TEMPORARY TABLE, and
665
709
    or for an intermediate table used in ALTER.
666
710
    XXX Why are internal temporary tables added to this list?
667
711
  */
668
 
  Table *temporary_tables;
 
712
  TABLE *temporary_tables;
669
713
  /**
670
714
    List of tables that were opened with HANDLER OPEN and are
671
715
    still in use by this thread.
672
716
  */
673
 
  Table *handler_tables;
674
 
  Table *derived_tables;
 
717
  TABLE *handler_tables;
 
718
  TABLE *derived_tables;
675
719
  /*
676
720
    During a MySQL session, one can lock tables in two modes: automatic
677
721
    or manual. In automatic mode all necessary tables are locked just before
685
729
    the 'LOCK_TABLES' chapter of the MySQL manual.
686
730
    See also lock_tables() for details.
687
731
  */
688
 
  DRIZZLE_LOCK *lock;
 
732
  MYSQL_LOCK *lock;
689
733
  /*
690
734
    Tables that were locked with explicit or implicit LOCK TABLES.
691
735
    (Implicit LOCK TABLES happens when we are prelocking tables for
692
736
     execution of statement which uses stored routines. See description
693
737
     THD::prelocked_mode for more info.)
694
738
  */
695
 
  DRIZZLE_LOCK *locked_tables;
 
739
  MYSQL_LOCK *locked_tables;
696
740
 
697
741
  /*
698
742
    CREATE-SELECT keeps an extra lock for the table being
699
743
    created. This field is used to keep the extra lock available for
700
744
    lower level routines, which would otherwise miss that lock.
701
745
   */
702
 
  DRIZZLE_LOCK *extra_lock;
 
746
  MYSQL_LOCK *extra_lock;
703
747
 
704
748
  ulong version;
705
 
  uint32_t current_tablenr;
 
749
  uint current_tablenr;
706
750
 
707
751
  enum enum_flags {
708
752
    BACKUPS_AVAIL = (1U << 0)     /* There are backups available */
711
755
  /*
712
756
    Flags with information about the open tables state.
713
757
  */
714
 
  uint32_t state_flags;
 
758
  uint state_flags;
715
759
 
716
760
  /*
717
761
    This constructor serves for creation of Open_tables_state instances
734
778
  }
735
779
};
736
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
 
737
809
 
738
810
/* Flags for the THD::system_thread variable */
739
811
enum enum_thread_type
781
853
    @param thd the calling thread
782
854
    @return true if the error is handled
783
855
  */
784
 
  virtual bool handle_error(uint32_t sql_errno,
 
856
  virtual bool handle_error(uint sql_errno,
785
857
                            const char *message,
786
 
                            DRIZZLE_ERROR::enum_warning_level level,
 
858
                            MYSQL_ERROR::enum_warning_level level,
787
859
                            THD *thd) = 0;
788
860
};
789
861
 
820
892
                     uint64_t last_insert_id_arg,
821
893
                     const char *message);
822
894
  void set_eof_status(THD *thd);
823
 
  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);
824
896
 
825
897
  void disable_status();
826
898
 
836
908
  const char *message() const
837
909
  { assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
838
910
 
839
 
  uint32_t sql_errno() const
 
911
  uint sql_errno() const
840
912
  { assert(m_status == DA_ERROR); return m_sql_errno; }
841
913
 
842
 
  uint32_t server_status() const
 
914
  uint server_status() const
843
915
  {
844
916
    assert(m_status == DA_OK || m_status == DA_EOF);
845
917
    return m_server_status;
851
923
  uint64_t last_insert_id() const
852
924
  { assert(m_status == DA_OK); return m_last_insert_id; }
853
925
 
854
 
  uint32_t total_warn_count() const
 
926
  uint total_warn_count() const
855
927
  {
856
928
    assert(m_status == DA_OK || m_status == DA_EOF);
857
929
    return m_total_warn_count;
861
933
 
862
934
private:
863
935
  /** Message buffer. Can be used by OK or ERROR status. */
864
 
  char m_message[DRIZZLE_ERRMSG_SIZE];
 
936
  char m_message[MYSQL_ERRMSG_SIZE];
865
937
  /**
866
938
    SQL error number. One of ER_ codes from share/errmsg.txt.
867
939
    Set by set_error_status.
868
940
  */
869
 
  uint32_t m_sql_errno;
 
941
  uint m_sql_errno;
870
942
 
871
943
  /**
872
944
    Copied from thd->server_status when the diagnostics area is assigned.
876
948
    thd->server_status&= ~...
877
949
    Assigned by OK, EOF or ERROR.
878
950
  */
879
 
  uint32_t m_server_status;
 
951
  uint m_server_status;
880
952
  /**
881
953
    The number of rows affected by the last statement. This is
882
954
    semantically close to thd->row_count_func, but has a different
1004
1076
    Set it using the  thd_proc_info(THD *thread, const char *message)
1005
1077
    macro/function.
1006
1078
  */
1007
 
  void        set_proc_info(const char *info) { proc_info= info; }
1008
 
  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;
1009
1086
 
1010
1087
  /*
1011
1088
    Used in error messages to tell user in what part of MySQL we found an
1024
1101
    points to a lock object if the lock is present. See item_func.cc and
1025
1102
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK. 
1026
1103
  */
1027
 
  uint32_t dbug_sentry; // watch out for memory corruption
 
1104
  uint dbug_sentry; // watch out for memory corruption
1028
1105
  struct st_my_thread_var *mysys_var;
1029
1106
  /*
1030
1107
    Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1031
1108
    first byte of the packet in do_command()
1032
1109
  */
1033
1110
  enum enum_server_command command;
1034
 
  uint32_t     server_id;
1035
 
  uint32_t     file_id;                 // for LOAD DATA INFILE
 
1111
  uint32     server_id;
 
1112
  uint32     file_id;                   // for LOAD DATA INFILE
1036
1113
  /* remote (peer) port */
1037
 
  uint16_t peer_port;
 
1114
  uint16 peer_port;
1038
1115
  time_t     start_time, user_time;
1039
1116
  uint64_t  connect_utime, thr_create_utime; // track down slow pthread_create
1040
1117
  uint64_t  start_utime, utime_after_lock;
1042
1119
  thr_lock_type update_lock_default;
1043
1120
 
1044
1121
  /* <> 0 if we are inside of trigger or stored function. */
1045
 
  uint32_t in_sub_stmt;
 
1122
  uint in_sub_stmt;
1046
1123
 
1047
1124
  /* container for handler's private per-connection data */
1048
1125
  Ha_data ha_data[MAX_HA];
1049
1126
 
1050
1127
  /* Place to store various things */
1051
1128
  void *thd_marker;
 
1129
#ifndef MYSQL_CLIENT
1052
1130
  int binlog_setup_trx_data();
1053
1131
 
1054
1132
  /*
1056
1134
  */
1057
1135
  void binlog_start_trans_and_stmt();
1058
1136
  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);
 
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);
1066
1144
 
1067
 
  void set_server_id(uint32_t sid) { server_id = sid; }
 
1145
  void set_server_id(uint32 sid) { server_id = sid; }
1068
1146
 
1069
1147
  /*
1070
1148
    Member functions to handle pending event for row-level logging.
1071
1149
  */
1072
1150
  template <class RowsEventT> Rows_log_event*
1073
 
    binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
1151
    binlog_prepare_pending_rows_event(TABLE* table, uint32 serv_id,
1074
1152
                                      size_t needed,
1075
1153
                                      bool is_transactional,
1076
1154
                                      RowsEventT* hint);
1079
1157
  int binlog_flush_pending_rows_event(bool stmt_end);
1080
1158
 
1081
1159
private:
1082
 
  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
1083
1161
 
1084
1162
  enum enum_binlog_flag {
1085
1163
    BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1090
1168
     Flags with per-thread information regarding the status of the
1091
1169
     binary log.
1092
1170
   */
1093
 
  uint32_t binlog_flags;
 
1171
  uint32 binlog_flags;
1094
1172
public:
1095
 
  uint32_t get_binlog_table_maps() const {
 
1173
  uint get_binlog_table_maps() const {
1096
1174
    return binlog_table_maps;
1097
1175
  }
1098
1176
  void clear_binlog_table_maps() {
1099
1177
    binlog_table_maps= 0;
1100
1178
  }
 
1179
#endif /* MYSQL_CLIENT */
1101
1180
 
1102
1181
public:
1103
1182
 
1114
1193
       List contain only transactional tables, that not invalidated in query
1115
1194
       cache (instead of full list of changed in transaction tables).
1116
1195
    */
1117
 
    CHANGED_TableList* changed_tables;
 
1196
    CHANGED_TABLE_LIST* changed_tables;
1118
1197
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
1119
1198
    void cleanup()
1120
1199
    {
1124
1203
    }
1125
1204
    st_transactions()
1126
1205
    {
1127
 
      memset(this, 0, sizeof(*this));
 
1206
      bzero((char*)this, sizeof(*this));
1128
1207
      xid_state.xid.null();
1129
1208
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
1130
1209
    }
1131
1210
  } transaction;
1132
1211
  Field      *dup_field;
1133
1212
  sigset_t signals;
 
1213
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1214
  Vio* active_vio;
 
1215
#endif
1134
1216
  /*
1135
1217
    This is to track items changed during execution of a prepared
1136
1218
    statement/stored procedure. It's created by
1140
1222
  */
1141
1223
  Item_change_list change_list;
1142
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;
1143
1238
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
1144
1239
  bool arg_of_last_insert_id_function;
1145
1240
  /*
1271
1366
  inline void force_one_auto_inc_interval(uint64_t next_id)
1272
1367
  {
1273
1368
    auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
1274
 
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
 
1369
    auto_inc_intervals_forced.append(next_id, ULONGLONG_MAX, 0);
1275
1370
  }
1276
1371
 
1277
1372
  uint64_t  limit_found_rows;
1298
1393
  */
1299
1394
  table_map  used_tables;
1300
1395
  USER_CONN *user_connect;
1301
 
  const CHARSET_INFO *db_charset;
 
1396
  CHARSET_INFO *db_charset;
1302
1397
  /*
1303
1398
    FIXME: this, and some other variables like 'count_cuted_fields'
1304
1399
    maybe should be statement/cursor local, that is, moved to Statement
1305
1400
    class. With current implementation warnings produced in each prepared
1306
1401
    statement/cursor settle here.
1307
1402
  */
1308
 
  List       <DRIZZLE_ERROR> warn_list;
1309
 
  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];
1310
1405
  uint       total_warn_count;
1311
1406
  Diagnostics_area main_da;
1312
1407
 
1337
1432
  uint       tmp_table, global_read_lock;
1338
1433
  uint       server_status,open_options;
1339
1434
  enum enum_thread_type system_thread;
1340
 
  uint32_t       select_number;             //number of select (used for EXPLAIN)
 
1435
  uint       select_number;             //number of select (used for EXPLAIN)
1341
1436
  /* variables.transaction_isolation is reset to this after each commit */
1342
1437
  enum_tx_isolation session_tx_isolation;
1343
1438
  enum_check_fields count_cuted_fields;
1425
1520
  /* Used by the sys_var class to store temporary values */
1426
1521
  union
1427
1522
  {
1428
 
    bool   bool_value;
 
1523
    my_bool   my_bool_value;
1429
1524
    long      long_value;
1430
1525
    ulong     ulong_value;
1431
1526
    uint64_t uint64_t_value;
1466
1561
  */
1467
1562
  Lex_input_stream *m_lip;
1468
1563
 
 
1564
  /*
 
1565
    @todo The following is a work around for online backup and the DDL blocker.
 
1566
          It should be removed when the generalized solution is in place.
 
1567
          This is needed to ensure the restore (which uses DDL) is not blocked
 
1568
          when the DDL blocker is engaged.
 
1569
  */
 
1570
  my_bool DDL_exception; // Allow some DDL if there is an exception
 
1571
 
1469
1572
  THD();
1470
1573
  ~THD();
1471
1574
 
1484
1587
  void cleanup(void);
1485
1588
  void cleanup_after_query();
1486
1589
  bool store_globals();
 
1590
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1591
  inline void set_active_vio(Vio* vio)
 
1592
  {
 
1593
    pthread_mutex_lock(&LOCK_delete);
 
1594
    active_vio = vio;
 
1595
    pthread_mutex_unlock(&LOCK_delete);
 
1596
  }
 
1597
  inline void clear_active_vio()
 
1598
  {
 
1599
    pthread_mutex_lock(&LOCK_delete);
 
1600
    active_vio = 0;
 
1601
    pthread_mutex_unlock(&LOCK_delete);
 
1602
  }
 
1603
  void close_active_vio();
 
1604
#endif
1487
1605
  void awake(THD::killed_state state_to_set);
1488
1606
 
 
1607
#ifndef MYSQL_CLIENT
1489
1608
  enum enum_binlog_query_type {
1490
1609
    /*
1491
1610
      The query can be logged row-based or statement-based
1501
1620
      The query represents a change to a table in the "mysql"
1502
1621
      database and is currently mapped to ROW_QUERY_TYPE.
1503
1622
    */
1504
 
    DRIZZLE_QUERY_TYPE,
 
1623
    MYSQL_QUERY_TYPE,
1505
1624
    QUERY_TYPE_COUNT
1506
1625
  };
1507
1626
  
1509
1628
                   char const *query, ulong query_len,
1510
1629
                   bool is_trans, bool suppress_use,
1511
1630
                   THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
 
1631
#endif
1512
1632
 
1513
1633
  /*
1514
1634
    For enter_cond() / exit_cond() to work the mutex must be got before
1577
1697
  }
1578
1698
 
1579
1699
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1580
 
                              const char* str, uint32_t length,
 
1700
                              const char* str, uint length,
1581
1701
                              bool allocate_lex_string);
1582
1702
 
1583
 
  bool convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1584
 
                      const char *from, uint32_t from_length,
1585
 
                      const CHARSET_INFO * const from_cs);
1586
 
 
1587
 
  bool convert_string(String *s, const CHARSET_INFO * const from_cs, const CHARSET_INFO * const to_cs);
1588
 
 
1589
 
  void add_changed_table(Table *table);
 
1703
  bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
 
1704
                      const char *from, uint from_length,
 
1705
                      CHARSET_INFO *from_cs);
 
1706
 
 
1707
  bool convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs);
 
1708
 
 
1709
  void add_changed_table(TABLE *table);
1590
1710
  void add_changed_table(const char *key, long key_length);
1591
 
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
 
1711
  CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1592
1712
  int send_explain_fields(select_result *result);
1593
1713
  /**
1594
1714
    Clear the current error, if any.
1605
1725
    return;
1606
1726
  }
1607
1727
  inline bool vio_ok() const { return net.vio != 0; }
1608
 
 
 
1728
  /** Return false if connection to client is broken. */
 
1729
  bool vio_is_connected();
1609
1730
  /**
1610
1731
    Mark the current error as fatal. Warning: this does not
1611
1732
    set any error, it sets a property of the error, so must be
1630
1751
    To raise this flag, use my_error().
1631
1752
  */
1632
1753
  inline bool is_error() const { return main_da.is_error(); }
1633
 
  inline const CHARSET_INFO *charset() { return variables.character_set_client; }
 
1754
  inline CHARSET_INFO *charset() { return variables.character_set_client; }
1634
1755
  void update_charset();
1635
1756
 
1636
1757
  void change_item_tree(Item **place, Item *new_value)
1637
1758
  {
 
1759
    /* TODO: check for OOM condition here */
 
1760
    if (!stmt_arena->is_conventional())
 
1761
      nocheck_register_item_tree_change(place, *place, mem_root);
1638
1762
    *place= new_value;
1639
1763
  }
1640
1764
  void nocheck_register_item_tree_change(Item **place, Item *old_value,
1651
1775
    killed_state killed_val; /* to cache the volatile 'killed' */
1652
1776
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1653
1777
  }
1654
 
  void send_kill_message() const;
 
1778
  inline void send_kill_message() const
 
1779
  {
 
1780
    int err= killed_errno();
 
1781
    if (err)
 
1782
      my_message(err, ER(err), MYF(0));
 
1783
  }
1655
1784
  /* return true if we will abort query if we make a warning now */
1656
1785
  inline bool really_abort_on_warning()
1657
1786
  {
1658
1787
    return (abort_on_warning);
1659
1788
  }
1660
1789
  void set_status_var_init();
 
1790
  bool is_context_analysis_only()
 
1791
    { return lex->view_prepare_mode; }
1661
1792
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
1662
1793
  void restore_backup_open_tables_state(Open_tables_state *backup);
 
1794
  void restore_sub_statement_state(Sub_statement_state *backup);
 
1795
  void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
 
1796
  void restore_active_arena(Query_arena *set, Query_arena *backup);
1663
1797
 
1664
1798
  inline void set_current_stmt_binlog_row_based_if_mixed()
1665
1799
  {
1738
1872
      memcpy(db, new_db, new_db_len+1);
1739
1873
    else
1740
1874
    {
1741
 
      if (db)
1742
 
        free(db);
 
1875
      x_free(db);
1743
1876
      if (new_db)
1744
1877
        db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR));
1745
1878
      else
1770
1903
    allocate memory for a deep copy: current database may be freed after
1771
1904
    a statement is parsed but before it's executed.
1772
1905
  */
1773
 
  bool copy_db_to(char **p_db, size_t *p_db_length);
 
1906
  bool copy_db_to(char **p_db, size_t *p_db_length)
 
1907
  {
 
1908
    if (db == NULL)
 
1909
    {
 
1910
      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
 
1911
      return true;
 
1912
    }
 
1913
    *p_db= strmake(db, db_length);
 
1914
    *p_db_length= db_length;
 
1915
    return false;
 
1916
  }
1774
1917
  thd_scheduler scheduler;
1775
1918
 
1776
1919
public:
1786
1929
    @param level the error level
1787
1930
    @return true if the error is handled
1788
1931
  */
1789
 
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1790
 
                            DRIZZLE_ERROR::enum_warning_level level);
 
1932
  virtual bool handle_error(uint sql_errno, const char *message,
 
1933
                            MYSQL_ERROR::enum_warning_level level);
1791
1934
 
1792
1935
  /**
1793
1936
    Remove the error handler last pushed.
1795
1938
  void pop_internal_handler();
1796
1939
 
1797
1940
private:
1798
 
  const char *proc_info;
1799
 
 
1800
1941
  /** The current internal error handler for this thread, or NULL. */
1801
1942
  Internal_error_handler *m_internal_handler;
1802
1943
  /**
1858
1999
  bool opt_enclosed;
1859
2000
  bool dumpfile;
1860
2001
  ulong skip_lines;
1861
 
  const CHARSET_INFO *cs;
 
2002
  CHARSET_INFO *cs;
1862
2003
  sql_exchange(char *name, bool dumpfile_flag,
1863
2004
               enum_filetype filetype_arg= FILETYPE_CSV);
1864
2005
};
1878
2019
public:
1879
2020
  select_result();
1880
2021
  virtual ~select_result() {};
1881
 
  virtual int prepare(List<Item> &list __attribute__((unused)),
 
2022
  virtual int prepare(List<Item> &list __attribute__((__unused__)),
1882
2023
                      SELECT_LEX_UNIT *u)
1883
2024
  {
1884
2025
    unit= u;
1890
2031
    we need to know number of columns in the result set (if
1891
2032
    there is a result set) apart from sending columns metadata.
1892
2033
  */
1893
 
  virtual uint32_t field_count(List<Item> &fields) const
 
2034
  virtual uint field_count(List<Item> &fields) const
1894
2035
  { return fields.elements; }
1895
 
  virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
 
2036
  virtual bool send_fields(List<Item> &list, uint flags)=0;
1896
2037
  virtual bool send_data(List<Item> &items)=0;
1897
 
  virtual bool initialize_tables (JOIN  __attribute__((unused)) *join=0)
 
2038
  virtual bool initialize_tables (JOIN  __attribute__((__unused__)) *join=0)
1898
2039
  { return 0; }
1899
 
  virtual void send_error(uint32_t errcode,const char *err);
 
2040
  virtual void send_error(uint errcode,const char *err);
1900
2041
  virtual bool send_eof()=0;
1901
2042
  /**
1902
2043
    Check if this query returns a result set and therefore is allowed in
1927
2068
{
1928
2069
public:
1929
2070
  select_result_interceptor() {}              /* Remove gcc warning */
1930
 
  uint32_t field_count(List<Item> &fields __attribute__((unused))) const
 
2071
  uint field_count(List<Item> &fields __attribute__((__unused__))) const
1931
2072
  { return 0; }
1932
 
  bool send_fields(List<Item> &fields __attribute__((unused)),
1933
 
                   uint32_t flag __attribute__((unused))) { return false; }
 
2073
  bool send_fields(List<Item> &fields __attribute__((__unused__)),
 
2074
                   uint flag __attribute__((__unused__))) { return false; }
1934
2075
};
1935
2076
 
1936
2077
 
1943
2084
  bool is_result_set_started;
1944
2085
public:
1945
2086
  select_send() :is_result_set_started(false) {}
1946
 
  bool send_fields(List<Item> &list, uint32_t flags);
 
2087
  bool send_fields(List<Item> &list, uint flags);
1947
2088
  bool send_data(List<Item> &items);
1948
2089
  bool send_eof();
1949
2090
  virtual bool check_simple_select() const { return false; }
1964
2105
  select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1965
2106
  { path[0]=0; }
1966
2107
  ~select_to_file();
1967
 
  void send_error(uint32_t errcode,const char *err);
 
2108
  void send_error(uint errcode,const char *err);
1968
2109
  bool send_eof();
1969
2110
  void cleanup();
1970
2111
};
1980
2121
 
1981
2122
 
1982
2123
class select_export :public select_to_file {
1983
 
  uint32_t field_term_length;
 
2124
  uint field_term_length;
1984
2125
  int field_sep_char,escape_char,line_sep_char;
1985
2126
  int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1986
2127
  /*
2020
2161
 
2021
2162
class select_insert :public select_result_interceptor {
2022
2163
 public:
2023
 
  TableList *table_list;
2024
 
  Table *table;
 
2164
  TABLE_LIST *table_list;
 
2165
  TABLE *table;
2025
2166
  List<Item> *fields;
2026
2167
  uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2027
2168
  COPY_INFO info;
2028
2169
  bool insert_into_view;
2029
 
  select_insert(TableList *table_list_par,
2030
 
                Table *table_par, List<Item> *fields_par,
 
2170
  select_insert(TABLE_LIST *table_list_par,
 
2171
                TABLE *table_par, List<Item> *fields_par,
2031
2172
                List<Item> *update_fields, List<Item> *update_values,
2032
2173
                enum_duplicates duplic, bool ignore);
2033
2174
  ~select_insert();
2036
2177
  bool send_data(List<Item> &items);
2037
2178
  virtual void store_values(List<Item> &values);
2038
2179
  virtual bool can_rollback_data() { return 0; }
2039
 
  void send_error(uint32_t errcode,const char *err);
 
2180
  void send_error(uint errcode,const char *err);
2040
2181
  bool send_eof();
2041
2182
  void abort();
2042
2183
  /* not implemented: select_insert is never re-used in prepared statements */
2045
2186
 
2046
2187
 
2047
2188
class select_create: public select_insert {
2048
 
  order_st *group;
2049
 
  TableList *create_table;
 
2189
  ORDER *group;
 
2190
  TABLE_LIST *create_table;
2050
2191
  HA_CREATE_INFO *create_info;
2051
 
  TableList *select_tables;
 
2192
  TABLE_LIST *select_tables;
2052
2193
  Alter_info *alter_info;
2053
2194
  Field **field;
2054
2195
  /* lock data for tmp table */
2055
 
  DRIZZLE_LOCK *m_lock;
 
2196
  MYSQL_LOCK *m_lock;
2056
2197
  /* m_lock or thd->extra_lock */
2057
 
  DRIZZLE_LOCK **m_plock;
 
2198
  MYSQL_LOCK **m_plock;
2058
2199
public:
2059
 
  select_create (TableList *table_arg,
 
2200
  select_create (TABLE_LIST *table_arg,
2060
2201
                 HA_CREATE_INFO *create_info_par,
2061
2202
                 Alter_info *alter_info_arg,
2062
2203
                 List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2063
 
                 TableList *select_tables_arg)
 
2204
                 TABLE_LIST *select_tables_arg)
2064
2205
    :select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2065
2206
    create_table(table_arg),
2066
2207
    create_info(create_info_par),
2070
2211
    {}
2071
2212
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2072
2213
 
2073
 
  void binlog_show_create_table(Table **tables, uint32_t count);
 
2214
  void binlog_show_create_table(TABLE **tables, uint count);
2074
2215
  void store_values(List<Item> &values);
2075
 
  void send_error(uint32_t errcode,const char *err);
 
2216
  void send_error(uint errcode,const char *err);
2076
2217
  bool send_eof();
2077
2218
  void abort();
2078
2219
  virtual bool can_rollback_data() { return 1; }
2083
2224
  int prepare2(void) { return 0; }
2084
2225
};
2085
2226
 
2086
 
#include <storage/myisam/myisam.h>
 
2227
#include <myisam.h>
2087
2228
 
2088
2229
/* 
2089
2230
  Param to create temporary tables when doing SELECT:s 
2103
2244
  List<Item> save_copy_funcs;
2104
2245
  Copy_field *copy_field, *copy_field_end;
2105
2246
  Copy_field *save_copy_field, *save_copy_field_end;
2106
 
  unsigned char     *group_buff;
 
2247
  uchar     *group_buff;
2107
2248
  Item      **items_to_copy;                    /* Fields in tmp table */
2108
2249
  MI_COLUMNDEF *recinfo,*start_recinfo;
2109
2250
  KEY *keyinfo;
2110
2251
  ha_rows end_write_records;
2111
2252
  uint  field_count,sum_func_count,func_count;
2112
 
  uint32_t  hidden_field_count;
 
2253
  uint  hidden_field_count;
2113
2254
  uint  group_parts,group_length,group_null_parts;
2114
2255
  uint  quick_group;
2115
2256
  bool  using_indirect_summary_function;
2116
2257
  /* If >0 convert all blob fields to varchar(convert_blob_length) */
2117
 
  uint32_t  convert_blob_length; 
2118
 
  const CHARSET_INFO *table_charset; 
 
2258
  uint  convert_blob_length; 
 
2259
  CHARSET_INFO *table_charset; 
2119
2260
  bool schema_table;
2120
2261
  /*
2121
2262
    True if GROUP BY and its aggregate functions are already computed
2157
2298
{
2158
2299
  TMP_TABLE_PARAM tmp_table_param;
2159
2300
public:
2160
 
  Table *table;
 
2301
  TABLE *table;
2161
2302
 
2162
2303
  select_union() :table(0) {}
2163
2304
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2224
2365
  Field *field;                         /* Field to sort */
2225
2366
  Item  *item;                          /* Item if not sorting fields */
2226
2367
  uint   length;                        /* Length of sort field */
2227
 
  uint32_t   suffix_length;                 /* Length suffix (0-4) */
 
2368
  uint   suffix_length;                 /* Length suffix (0-4) */
2228
2369
  Item_result result_type;              /* Type of item */
2229
2370
  bool reverse;                         /* if descending sort */
2230
2371
  bool need_strxnfrm;                   /* If we have to use strxnfrm() */
2232
2373
 
2233
2374
 
2234
2375
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 */
 
2376
  uint index;                                   /* 0 or 1 */
 
2377
  uint sort_orders;
 
2378
  uint change_pos;                              /* If sort-fields changed */
2238
2379
  char **buff;
2239
2380
  SORT_FIELD *sortorder;
2240
2381
} SORT_BUFFER;
2294
2435
  Item_result type;
2295
2436
  bool unsigned_flag;
2296
2437
 
2297
 
  double val_real(bool *null_value);
2298
 
  int64_t val_int(bool *null_value) const;
2299
 
  String *val_str(bool *null_value, String *str, uint32_t decimals);
2300
 
  my_decimal *val_decimal(bool *null_value, my_decimal *result);
 
2438
  double val_real(my_bool *null_value);
 
2439
  int64_t val_int(my_bool *null_value) const;
 
2440
  String *val_str(my_bool *null_value, String *str, uint decimals);
 
2441
  my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
2301
2442
  DTCollation collation;
2302
2443
};
2303
2444
 
2316
2457
  uint64_t max_in_memory_size;
2317
2458
  IO_CACHE file;
2318
2459
  TREE tree;
2319
 
  unsigned char *record_pointers;
 
2460
  uchar *record_pointers;
2320
2461
  bool flush();
2321
 
  uint32_t size;
 
2462
  uint size;
2322
2463
 
2323
2464
public:
2324
2465
  ulong elements;
2325
2466
  Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2326
 
         uint32_t size_arg, uint64_t max_in_memory_size_arg);
 
2467
         uint size_arg, uint64_t max_in_memory_size_arg);
2327
2468
  ~Unique();
2328
2469
  ulong elements_in_tree() { return tree.elements_in_tree; }
2329
2470
  inline bool unique_add(void *ptr)
2333
2474
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2334
2475
  }
2335
2476
 
2336
 
  bool get(Table *table);
2337
 
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, 
 
2477
  bool get(TABLE *table);
 
2478
  static double get_use_cost(uint *buffer, uint nkeys, uint key_size, 
2338
2479
                             uint64_t max_in_memory_size);
2339
 
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, 
 
2480
  inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size, 
2340
2481
                                            uint64_t max_in_memory_size)
2341
2482
  {
2342
2483
    register uint64_t max_elems_in_tree=
2347
2488
  void reset();
2348
2489
  bool walk(tree_walk_action action, void *walk_action_arg);
2349
2490
 
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);
 
2491
  friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
 
2492
  friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2352
2493
};
2353
2494
 
2354
2495
 
2355
2496
class multi_delete :public select_result_interceptor
2356
2497
{
2357
 
  TableList *delete_tables, *table_being_deleted;
 
2498
  TABLE_LIST *delete_tables, *table_being_deleted;
2358
2499
  Unique **tempfiles;
2359
2500
  ha_rows deleted, found;
2360
 
  uint32_t num_of_tables;
 
2501
  uint num_of_tables;
2361
2502
  int error;
2362
2503
  bool do_delete;
2363
2504
  /* True if at least one table we delete from is transactional */
2372
2513
  bool error_handled;
2373
2514
 
2374
2515
public:
2375
 
  multi_delete(TableList *dt, uint32_t num_of_tables);
 
2516
  multi_delete(TABLE_LIST *dt, uint num_of_tables);
2376
2517
  ~multi_delete();
2377
2518
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2378
2519
  bool send_data(List<Item> &items);
2379
2520
  bool initialize_tables (JOIN *join);
2380
 
  void send_error(uint32_t errcode,const char *err);
 
2521
  void send_error(uint errcode,const char *err);
2381
2522
  int  do_deletes();
2382
2523
  bool send_eof();
2383
2524
  virtual void abort();
2386
2527
 
2387
2528
class multi_update :public select_result_interceptor
2388
2529
{
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;
 
2530
  TABLE_LIST *all_tables; /* query/update command tables */
 
2531
  TABLE_LIST *leaves;     /* list of leves of join table tree */
 
2532
  TABLE_LIST *update_tables, *table_being_updated;
 
2533
  TABLE **tmp_tables, *main_table, *table_to_update;
2393
2534
  TMP_TABLE_PARAM *tmp_table_param;
2394
2535
  ha_rows updated, found;
2395
2536
  List <Item> *fields, *values;
2396
2537
  List <Item> **fields_for_table, **values_for_table;
2397
 
  uint32_t table_count;
 
2538
  uint table_count;
2398
2539
  /*
2399
2540
   List of tables referenced in the CHECK OPTION condition of
2400
2541
   the updated view excluding the updated table. 
2401
2542
  */
2402
 
  List <Table> unupdated_check_opt_tables;
 
2543
  List <TABLE> unupdated_check_opt_tables;
2403
2544
  Copy_field *copy_field;
2404
2545
  enum enum_duplicates handle_duplicates;
2405
2546
  bool do_update, trans_safe;
2413
2554
  bool error_handled;
2414
2555
 
2415
2556
public:
2416
 
  multi_update(TableList *ut, TableList *leaves_list,
 
2557
  multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2417
2558
               List<Item> *fields, List<Item> *values,
2418
2559
               enum_duplicates handle_duplicates, bool ignore);
2419
2560
  ~multi_update();
2420
2561
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2421
2562
  bool send_data(List<Item> &items);
2422
2563
  bool initialize_tables (JOIN *join);
2423
 
  void send_error(uint32_t errcode,const char *err);
 
2564
  void send_error(uint errcode,const char *err);
2424
2565
  int  do_updates();
2425
2566
  bool send_eof();
2426
2567
  virtual void abort();
2430
2571
public:
2431
2572
  LEX_STRING s;
2432
2573
  bool local;
2433
 
  uint32_t offset;
 
2574
  uint offset;
2434
2575
  enum_field_types type;
2435
 
  my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
 
2576
  my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2436
2577
    :s(j), local(i), offset(o), type(t)
2437
2578
  {}
2438
2579
  ~my_var() {}
2466
2607
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2467
2608
                        STATUS_VAR *dec_var);
2468
2609
 
2469
 
#endif /* DRIZZLE_SERVER */
 
2610
#endif /* MYSQL_SERVER */