~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_class.h

  • Committer: Mark Atwood
  • Date: 2008-07-12 07:25:25 UTC
  • mto: This revision was merged to the branch mainline in revision 139.
  • Revision ID: me@mark.atwood.name-20080712072525-s1dq9mtwo5td7af7
more hackery to get plugin UDFs working

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
/**
 
237
  Query_cache_tls -- query cache thread local data.
 
238
*/
 
239
 
 
240
struct Query_cache_block;
 
241
 
 
242
struct Query_cache_tls
 
243
{
 
244
  /*
 
245
    'first_query_block' should be accessed only via query cache
 
246
    functions and methods to maintain proper locking.
 
247
  */
 
248
  Query_cache_block *first_query_block;
 
249
  void set_first_query_block(Query_cache_block *first_query_block_arg)
 
250
  {
 
251
    first_query_block= first_query_block_arg;
 
252
  }
 
253
 
 
254
  Query_cache_tls() :first_query_block(NULL) {}
 
255
};
 
256
 
 
257
#include "sql_lex.h"                            /* Must be here */
 
258
 
235
259
class select_result;
236
260
class Time_zone;
237
261
 
253
277
  */ 
254
278
  ulong dynamic_variables_version;
255
279
  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 */
 
280
  uint dynamic_variables_head;  /* largest valid variable offset */
 
281
  uint dynamic_variables_size;  /* how many bytes are in use */
258
282
  
259
 
  uint64_t myisam_max_extra_sort_file_size;
260
 
  uint64_t myisam_max_sort_file_size;
261
 
  uint64_t max_heap_table_size;
262
 
  uint64_t tmp_table_size;
263
 
  uint64_t long_query_time;
 
283
  ulonglong myisam_max_extra_sort_file_size;
 
284
  ulonglong myisam_max_sort_file_size;
 
285
  ulonglong max_heap_table_size;
 
286
  ulonglong tmp_table_size;
 
287
  ulonglong long_query_time;
264
288
  ha_rows select_limit;
265
289
  ha_rows max_join_size;
266
290
  ulong auto_increment_increment, auto_increment_offset;
320
344
  */
321
345
  my_thread_id pseudo_thread_id;
322
346
 
323
 
  bool low_priority_updates;
324
 
  bool new_mode;
 
347
  my_bool low_priority_updates;
 
348
  my_bool new_mode;
325
349
  /* 
326
350
    compatibility option:
327
351
      - index usage hints (USE INDEX without a FOR clause) behave as in 5.0 
328
352
  */
329
 
  bool old_mode;
330
 
  bool engine_condition_pushdown;
331
 
  bool keep_files_on_create;
 
353
  my_bool old_mode;
 
354
  my_bool query_cache_wlock_invalidate;
 
355
  my_bool engine_condition_pushdown;
 
356
  my_bool keep_files_on_create;
332
357
 
333
 
  bool old_alter_table;
 
358
  my_bool old_alter_table;
334
359
 
335
360
  plugin_ref table_plugin;
336
361
 
337
362
  /* 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;
 
363
  CHARSET_INFO  *character_set_filesystem;
 
364
  CHARSET_INFO  *character_set_client;
 
365
  CHARSET_INFO  *character_set_results;
341
366
 
342
367
  /* 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;
 
368
  CHARSET_INFO  *collation_server;
 
369
  CHARSET_INFO  *collation_database;
 
370
  CHARSET_INFO  *collation_connection;
346
371
 
347
372
  /* Locale Support */
348
373
  MY_LOCALE *lc_time_names;
349
374
 
350
375
  Time_zone *time_zone;
351
376
 
352
 
  /* DATE, DATETIME and DRIZZLE_TIME formats */
 
377
  /* DATE, DATETIME and MYSQL_TIME formats */
353
378
  DATE_TIME_FORMAT *date_format;
354
379
  DATE_TIME_FORMAT *datetime_format;
355
380
  DATE_TIME_FORMAT *time_format;
356
 
  bool sysdate_is_now;
 
381
  my_bool sysdate_is_now;
357
382
 
358
383
};
359
384
 
360
 
#include "sql_lex.h"  /* only for SQLCOM_END */
361
385
 
362
386
/* per thread status variables */
363
387
 
364
388
typedef struct system_status_var
365
389
{
366
 
  uint64_t bytes_received;
367
 
  uint64_t bytes_sent;
 
390
  ulonglong bytes_received;
 
391
  ulonglong bytes_sent;
368
392
  ulong com_other;
369
393
  ulong com_stat[(uint) SQLCOM_END];
370
394
  ulong created_tmp_disk_tables;
442
466
 
443
467
void mark_transaction_to_rollback(THD *thd, bool all);
444
468
 
445
 
#ifdef DRIZZLE_SERVER
 
469
#ifdef MYSQL_SERVER
 
470
 
 
471
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
446
472
 
447
473
class Query_arena
448
474
{
453
479
  */
454
480
  Item *free_list;
455
481
  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
 
  { }
 
482
  bool is_backup_arena; /* True if this arena is used for backup. */
 
483
 
 
484
  /*
 
485
    The states relfects three diffrent life cycles for three
 
486
    different types of statements:
 
487
    Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
 
488
    Stored procedure:   INITIALIZED_FOR_SP -> EXECUTED.
 
489
    Other statements:   CONVENTIONAL_EXECUTION never changes.
 
490
  */
 
491
  enum enum_state
 
492
  {
 
493
    INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2,
 
494
    CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
 
495
  };
 
496
 
 
497
  enum_state state;
 
498
 
 
499
  /* We build without RTTI, so dynamic_cast can't be used. */
 
500
  enum Type
 
501
  {
 
502
    STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE
 
503
  };
 
504
 
 
505
  Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
 
506
    free_list(0), mem_root(mem_root_arg), state(state_arg)
 
507
  { INIT_ARENA_DBUG_INFO; }
460
508
  /*
461
509
    This constructor is used only when Query_arena is created as
462
510
    backup storage for another instance of Query_arena.
463
511
  */
464
 
  Query_arena() { }
 
512
  Query_arena() { INIT_ARENA_DBUG_INFO; }
465
513
 
466
514
  virtual ~Query_arena() {};
467
515
 
 
516
  inline bool is_conventional() const
 
517
  { assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
 
518
 
468
519
  inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
469
520
  inline void* calloc(size_t size)
470
521
  {
471
522
    void *ptr;
472
523
    if ((ptr=alloc_root(mem_root,size)))
473
 
      memset(ptr, 0, size);
 
524
      bzero(ptr, size);
474
525
    return ptr;
475
526
  }
476
527
  inline char *strdup(const char *str)
479
530
  { return strmake_root(mem_root,str,size); }
480
531
  inline void *memdup(const void *str, size_t size)
481
532
  { return memdup_root(mem_root,str,size); }
482
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
 
533
  inline void *memdup_w_gap(const void *str, size_t size, uint gap)
483
534
  {
484
535
    void *ptr;
485
536
    if ((ptr= alloc_root(mem_root,size+gap)))
487
538
    return ptr;
488
539
  }
489
540
 
 
541
  void set_query_arena(Query_arena *set);
 
542
 
490
543
  void free_items();
 
544
  /* Close the active state associated with execution of this statement */
 
545
  virtual void cleanup_stmt();
491
546
};
492
547
 
493
548
 
528
583
  */
529
584
  enum enum_mark_columns mark_used_columns;
530
585
 
 
586
  LEX_STRING name; /* name for named prepared statements */
531
587
  LEX *lex;                                     // parse tree descriptor
532
588
  /*
533
589
    Points to the query associated with this statement. It's const, but
552
608
    STATUS.
553
609
  */
554
610
  char *query;
555
 
  uint32_t query_length;                          // current query length
 
611
  uint32 query_length;                          // current query length
556
612
 
557
613
  /**
558
614
    Name of the current (default) database.
568
624
  */
569
625
 
570
626
  char *db;
571
 
  uint32_t db_length;
 
627
  uint db_length;
572
628
 
573
629
public:
574
630
 
575
631
  /* This constructor is called for backup statements */
576
632
  Statement() {}
577
633
 
578
 
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
 
634
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
 
635
            enum enum_state state_arg, ulong id_arg);
579
636
  ~Statement() {}
 
637
 
 
638
  /* Assign execution context (note: not all members) of given stmt to self */
 
639
  void set_statement(Statement *stmt);
 
640
  void set_n_backup_statement(Statement *stmt, Statement *backup);
 
641
  void restore_backup_statement(Statement *stmt, Statement *backup);
580
642
};
581
643
 
582
644
struct st_savepoint {
583
645
  struct st_savepoint *prev;
584
646
  char                *name;
585
 
  uint32_t                 length;
 
647
  uint                 length;
586
648
  Ha_trx_info         *ha_list;
587
649
};
588
650
 
620
682
    priv_user - The user privilege we are using. May be "" for anonymous user.
621
683
    ip - client IP
622
684
  */
623
 
  char *user; 
624
 
  char *ip;
 
685
  char   *host, *user, *priv_user, *ip;
 
686
  /* The host privilege we are using */
 
687
  char   priv_host[MAX_HOSTNAME];
 
688
  /* points to host if host is available, otherwise points to ip */
 
689
  const char *host_or_ip;
 
690
  ulong db_access;                     /* Privileges for current db */
625
691
 
626
692
  void init();
627
693
  void destroy();
628
694
  void skip_grants();
629
695
  inline char *priv_host_name()
630
696
  {
631
 
    return (ip ? ip : (char *)"%");
 
697
    return (*priv_host ? priv_host : (char *)"%");
632
698
  }
633
699
};
634
700
 
657
723
    List of regular tables in use by this thread. Contains temporary and
658
724
    base tables that were opened with @see open_tables().
659
725
  */
660
 
  Table *open_tables;
 
726
  TABLE *open_tables;
661
727
  /**
662
728
    List of temporary tables used by this thread. Contains user-level
663
729
    temporary tables, created with CREATE TEMPORARY TABLE, and
665
731
    or for an intermediate table used in ALTER.
666
732
    XXX Why are internal temporary tables added to this list?
667
733
  */
668
 
  Table *temporary_tables;
 
734
  TABLE *temporary_tables;
669
735
  /**
670
736
    List of tables that were opened with HANDLER OPEN and are
671
737
    still in use by this thread.
672
738
  */
673
 
  Table *handler_tables;
674
 
  Table *derived_tables;
 
739
  TABLE *handler_tables;
 
740
  TABLE *derived_tables;
675
741
  /*
676
742
    During a MySQL session, one can lock tables in two modes: automatic
677
743
    or manual. In automatic mode all necessary tables are locked just before
685
751
    the 'LOCK_TABLES' chapter of the MySQL manual.
686
752
    See also lock_tables() for details.
687
753
  */
688
 
  DRIZZLE_LOCK *lock;
 
754
  MYSQL_LOCK *lock;
689
755
  /*
690
756
    Tables that were locked with explicit or implicit LOCK TABLES.
691
757
    (Implicit LOCK TABLES happens when we are prelocking tables for
692
758
     execution of statement which uses stored routines. See description
693
759
     THD::prelocked_mode for more info.)
694
760
  */
695
 
  DRIZZLE_LOCK *locked_tables;
 
761
  MYSQL_LOCK *locked_tables;
696
762
 
697
763
  /*
698
764
    CREATE-SELECT keeps an extra lock for the table being
699
765
    created. This field is used to keep the extra lock available for
700
766
    lower level routines, which would otherwise miss that lock.
701
767
   */
702
 
  DRIZZLE_LOCK *extra_lock;
 
768
  MYSQL_LOCK *extra_lock;
703
769
 
704
770
  ulong version;
705
 
  uint32_t current_tablenr;
 
771
  uint current_tablenr;
706
772
 
707
773
  enum enum_flags {
708
774
    BACKUPS_AVAIL = (1U << 0)     /* There are backups available */
711
777
  /*
712
778
    Flags with information about the open tables state.
713
779
  */
714
 
  uint32_t state_flags;
 
780
  uint state_flags;
715
781
 
716
782
  /*
717
783
    This constructor serves for creation of Open_tables_state instances
734
800
  }
735
801
};
736
802
 
 
803
/**
 
804
  @class Sub_statement_state
 
805
  @brief Used to save context when executing a function or trigger
 
806
*/
 
807
 
 
808
/* Defines used for Sub_statement_state::in_sub_stmt */
 
809
 
 
810
#define SUB_STMT_TRIGGER 1
 
811
#define SUB_STMT_FUNCTION 2
 
812
 
 
813
 
 
814
class Sub_statement_state
 
815
{
 
816
public:
 
817
  ulonglong options;
 
818
  ulonglong first_successful_insert_id_in_prev_stmt;
 
819
  ulonglong first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
 
820
  Discrete_interval auto_inc_interval_for_cur_row;
 
821
  Discrete_intervals_list auto_inc_intervals_forced;
 
822
  ulonglong limit_found_rows;
 
823
  ha_rows    cuted_fields, sent_row_count, examined_row_count;
 
824
  ulong client_capabilities;
 
825
  uint in_sub_stmt;
 
826
  bool enable_slow_log;
 
827
  bool last_insert_id_used;
 
828
  SAVEPOINT *savepoints;
 
829
};
 
830
 
737
831
 
738
832
/* Flags for the THD::system_thread variable */
739
833
enum enum_thread_type
740
834
{
741
 
  NON_SYSTEM_THREAD,
742
 
  SYSTEM_THREAD_SLAVE_IO,
743
 
  SYSTEM_THREAD_SLAVE_SQL
 
835
  NON_SYSTEM_THREAD= 0,
 
836
  SYSTEM_THREAD_DELAYED_INSERT= 1,
 
837
  SYSTEM_THREAD_SLAVE_IO= 2,
 
838
  SYSTEM_THREAD_SLAVE_SQL= 4,
 
839
  SYSTEM_THREAD_NDBCLUSTER_BINLOG= 8,
 
840
  SYSTEM_THREAD_EVENT_SCHEDULER= 16,
 
841
  SYSTEM_THREAD_EVENT_WORKER= 32,
 
842
  SYSTEM_THREAD_BACKUP= 64
744
843
};
745
844
 
746
845
 
781
880
    @param thd the calling thread
782
881
    @return true if the error is handled
783
882
  */
784
 
  virtual bool handle_error(uint32_t sql_errno,
 
883
  virtual bool handle_error(uint sql_errno,
785
884
                            const char *message,
786
 
                            DRIZZLE_ERROR::enum_warning_level level,
 
885
                            MYSQL_ERROR::enum_warning_level level,
787
886
                            THD *thd) = 0;
788
887
};
789
888
 
817
916
  bool can_overwrite_status;
818
917
 
819
918
  void set_ok_status(THD *thd, ha_rows affected_rows_arg,
820
 
                     uint64_t last_insert_id_arg,
 
919
                     ulonglong last_insert_id_arg,
821
920
                     const char *message);
822
921
  void set_eof_status(THD *thd);
823
 
  void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
 
922
  void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
824
923
 
825
924
  void disable_status();
826
925
 
836
935
  const char *message() const
837
936
  { assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
838
937
 
839
 
  uint32_t sql_errno() const
 
938
  uint sql_errno() const
840
939
  { assert(m_status == DA_ERROR); return m_sql_errno; }
841
940
 
842
 
  uint32_t server_status() const
 
941
  uint server_status() const
843
942
  {
844
943
    assert(m_status == DA_OK || m_status == DA_EOF);
845
944
    return m_server_status;
848
947
  ha_rows affected_rows() const
849
948
  { assert(m_status == DA_OK); return m_affected_rows; }
850
949
 
851
 
  uint64_t last_insert_id() const
 
950
  ulonglong last_insert_id() const
852
951
  { assert(m_status == DA_OK); return m_last_insert_id; }
853
952
 
854
 
  uint32_t total_warn_count() const
 
953
  uint total_warn_count() const
855
954
  {
856
955
    assert(m_status == DA_OK || m_status == DA_EOF);
857
956
    return m_total_warn_count;
861
960
 
862
961
private:
863
962
  /** Message buffer. Can be used by OK or ERROR status. */
864
 
  char m_message[DRIZZLE_ERRMSG_SIZE];
 
963
  char m_message[MYSQL_ERRMSG_SIZE];
865
964
  /**
866
965
    SQL error number. One of ER_ codes from share/errmsg.txt.
867
966
    Set by set_error_status.
868
967
  */
869
 
  uint32_t m_sql_errno;
 
968
  uint m_sql_errno;
870
969
 
871
970
  /**
872
971
    Copied from thd->server_status when the diagnostics area is assigned.
876
975
    thd->server_status&= ~...
877
976
    Assigned by OK, EOF or ERROR.
878
977
  */
879
 
  uint32_t m_server_status;
 
978
  uint m_server_status;
880
979
  /**
881
980
    The number of rows affected by the last statement. This is
882
981
    semantically close to thd->row_count_func, but has a different
894
993
    thd->first_successful_insert_id_in_prev_stmt, which is used
895
994
    to implement LAST_INSERT_ID().
896
995
  */
897
 
  uint64_t   m_last_insert_id;
 
996
  ulonglong   m_last_insert_id;
898
997
  /** The total number of warnings. */
899
998
  uint       m_total_warn_count;
900
999
  enum_diagnostics_status m_status;
1004
1103
    Set it using the  thd_proc_info(THD *thread, const char *message)
1005
1104
    macro/function.
1006
1105
  */
1007
 
  void        set_proc_info(const char *info) { proc_info= info; }
1008
 
  const char* get_proc_info() const { return proc_info; }
 
1106
#define THD_SET_PROC_INFO(thd, info) \
 
1107
    (thd)->proc_info= (info)
 
1108
 
 
1109
  inline const char* get_proc_info() { return proc_info;}
 
1110
 
 
1111
  /* left public for the the storage engines, please avoid direct use */
 
1112
  const char *proc_info;
1009
1113
 
1010
1114
  /*
1011
1115
    Used in error messages to tell user in what part of MySQL we found an
1024
1128
    points to a lock object if the lock is present. See item_func.cc and
1025
1129
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK. 
1026
1130
  */
1027
 
  uint32_t dbug_sentry; // watch out for memory corruption
 
1131
  uint dbug_sentry; // watch out for memory corruption
1028
1132
  struct st_my_thread_var *mysys_var;
1029
1133
  /*
1030
1134
    Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1031
1135
    first byte of the packet in do_command()
1032
1136
  */
1033
1137
  enum enum_server_command command;
1034
 
  uint32_t     server_id;
1035
 
  uint32_t     file_id;                 // for LOAD DATA INFILE
 
1138
  uint32     server_id;
 
1139
  uint32     file_id;                   // for LOAD DATA INFILE
1036
1140
  /* remote (peer) port */
1037
 
  uint16_t peer_port;
 
1141
  uint16 peer_port;
1038
1142
  time_t     start_time, user_time;
1039
 
  uint64_t  connect_utime, thr_create_utime; // track down slow pthread_create
1040
 
  uint64_t  start_utime, utime_after_lock;
 
1143
  ulonglong  connect_utime, thr_create_utime; // track down slow pthread_create
 
1144
  ulonglong  start_utime, utime_after_lock;
1041
1145
  
1042
1146
  thr_lock_type update_lock_default;
1043
1147
 
1044
1148
  /* <> 0 if we are inside of trigger or stored function. */
1045
 
  uint32_t in_sub_stmt;
 
1149
  uint in_sub_stmt;
1046
1150
 
1047
1151
  /* container for handler's private per-connection data */
1048
1152
  Ha_data ha_data[MAX_HA];
1049
1153
 
1050
1154
  /* Place to store various things */
1051
1155
  void *thd_marker;
 
1156
#ifndef MYSQL_CLIENT
1052
1157
  int binlog_setup_trx_data();
1053
1158
 
1054
1159
  /*
1056
1161
  */
1057
1162
  void binlog_start_trans_and_stmt();
1058
1163
  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);
 
1164
  int binlog_write_table_map(TABLE *table, bool is_transactional);
 
1165
  int binlog_write_row(TABLE* table, bool is_transactional,
 
1166
                       const uchar *new_data);
 
1167
  int binlog_delete_row(TABLE* table, bool is_transactional,
 
1168
                        const uchar *old_data);
 
1169
  int binlog_update_row(TABLE* table, bool is_transactional,
 
1170
                        const uchar *old_data, const uchar *new_data);
1066
1171
 
1067
 
  void set_server_id(uint32_t sid) { server_id = sid; }
 
1172
  void set_server_id(uint32 sid) { server_id = sid; }
1068
1173
 
1069
1174
  /*
1070
1175
    Member functions to handle pending event for row-level logging.
1071
1176
  */
1072
1177
  template <class RowsEventT> Rows_log_event*
1073
 
    binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
1178
    binlog_prepare_pending_rows_event(TABLE* table, uint32 serv_id,
1074
1179
                                      size_t needed,
1075
1180
                                      bool is_transactional,
1076
1181
                                      RowsEventT* hint);
1079
1184
  int binlog_flush_pending_rows_event(bool stmt_end);
1080
1185
 
1081
1186
private:
1082
 
  uint32_t binlog_table_maps; // Number of table maps currently in the binlog
 
1187
  uint binlog_table_maps; // Number of table maps currently in the binlog
1083
1188
 
1084
1189
  enum enum_binlog_flag {
1085
1190
    BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1090
1195
     Flags with per-thread information regarding the status of the
1091
1196
     binary log.
1092
1197
   */
1093
 
  uint32_t binlog_flags;
 
1198
  uint32 binlog_flags;
1094
1199
public:
1095
 
  uint32_t get_binlog_table_maps() const {
 
1200
  uint get_binlog_table_maps() const {
1096
1201
    return binlog_table_maps;
1097
1202
  }
1098
1203
  void clear_binlog_table_maps() {
1099
1204
    binlog_table_maps= 0;
1100
1205
  }
 
1206
#endif /* MYSQL_CLIENT */
1101
1207
 
1102
1208
public:
1103
1209
 
1114
1220
       List contain only transactional tables, that not invalidated in query
1115
1221
       cache (instead of full list of changed in transaction tables).
1116
1222
    */
1117
 
    CHANGED_TableList* changed_tables;
 
1223
    CHANGED_TABLE_LIST* changed_tables;
1118
1224
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
1119
1225
    void cleanup()
1120
1226
    {
1124
1230
    }
1125
1231
    st_transactions()
1126
1232
    {
1127
 
      memset(this, 0, sizeof(*this));
 
1233
      bzero((char*)this, sizeof(*this));
1128
1234
      xid_state.xid.null();
1129
1235
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
1130
1236
    }
1131
1237
  } transaction;
1132
1238
  Field      *dup_field;
1133
1239
  sigset_t signals;
 
1240
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1241
  Vio* active_vio;
 
1242
#endif
1134
1243
  /*
1135
1244
    This is to track items changed during execution of a prepared
1136
1245
    statement/stored procedure. It's created by
1140
1249
  */
1141
1250
  Item_change_list change_list;
1142
1251
 
 
1252
  /*
 
1253
    A permanent memory area of the statement. For conventional
 
1254
    execution, the parsed tree and execution runtime reside in the same
 
1255
    memory root. In this case stmt_arena points to THD. In case of
 
1256
    a prepared statement or a stored procedure statement, thd->mem_root
 
1257
    conventionally points to runtime memory, and thd->stmt_arena
 
1258
    points to the memory of the PS/SP, where the parsed tree of the
 
1259
    statement resides. Whenever you need to perform a permanent
 
1260
    transformation of a parsed tree, you should allocate new memory in
 
1261
    stmt_arena, to allow correct re-execution of PS/SP.
 
1262
    Note: in the parser, stmt_arena == thd, even for PS/SP.
 
1263
  */
 
1264
  Query_arena *stmt_arena;
1143
1265
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
1144
1266
  bool arg_of_last_insert_id_function;
1145
1267
  /*
1154
1276
    It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#).
1155
1277
    It is returned by LAST_INSERT_ID().
1156
1278
  */
1157
 
  uint64_t  first_successful_insert_id_in_prev_stmt;
 
1279
  ulonglong  first_successful_insert_id_in_prev_stmt;
1158
1280
  /*
1159
1281
    Variant of the above, used for storing in statement-based binlog. The
1160
1282
    difference is that the one above can change as the execution of a stored
1161
1283
    function progresses, while the one below is set once and then does not
1162
1284
    change (which is the value which statement-based binlog needs).
1163
1285
  */
1164
 
  uint64_t  first_successful_insert_id_in_prev_stmt_for_binlog;
 
1286
  ulonglong  first_successful_insert_id_in_prev_stmt_for_binlog;
1165
1287
  /*
1166
1288
    This is the first autogenerated insert id which was *successfully*
1167
1289
    inserted by the current statement. It is maintained only to set
1168
1290
    first_successful_insert_id_in_prev_stmt when statement ends.
1169
1291
  */
1170
 
  uint64_t  first_successful_insert_id_in_cur_stmt;
 
1292
  ulonglong  first_successful_insert_id_in_cur_stmt;
1171
1293
  /*
1172
1294
    We follow this logic:
1173
1295
    - when stmt starts, first_successful_insert_id_in_prev_stmt contains the
1247
1369
    mode, row-based binlogging is used for such cases where two
1248
1370
    auto_increment columns are inserted.
1249
1371
  */
1250
 
  inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
 
1372
  inline void record_first_successful_insert_id_in_cur_stmt(ulonglong id_arg)
1251
1373
  {
1252
1374
    if (first_successful_insert_id_in_cur_stmt == 0)
1253
1375
      first_successful_insert_id_in_cur_stmt= id_arg;
1254
1376
  }
1255
 
  inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
 
1377
  inline ulonglong read_first_successful_insert_id_in_prev_stmt(void)
1256
1378
  {
1257
1379
    if (!stmt_depends_on_first_successful_insert_id_in_prev_stmt)
1258
1380
    {
1268
1390
    (mysqlbinlog). We'll soon add a variant which can take many intervals in
1269
1391
    argument.
1270
1392
  */
1271
 
  inline void force_one_auto_inc_interval(uint64_t next_id)
 
1393
  inline void force_one_auto_inc_interval(ulonglong next_id)
1272
1394
  {
1273
1395
    auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
1274
 
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
 
1396
    auto_inc_intervals_forced.append(next_id, ULONGLONG_MAX, 0);
1275
1397
  }
1276
1398
 
1277
 
  uint64_t  limit_found_rows;
1278
 
  uint64_t  options;           /* Bitmap of states */
1279
 
  int64_t   row_count_func;    /* For the ROW_COUNT() function */
 
1399
  ulonglong  limit_found_rows;
 
1400
  ulonglong  options;           /* Bitmap of states */
 
1401
  longlong   row_count_func;    /* For the ROW_COUNT() function */
1280
1402
  ha_rows    cuted_fields;
1281
1403
 
1282
1404
  /*
1298
1420
  */
1299
1421
  table_map  used_tables;
1300
1422
  USER_CONN *user_connect;
1301
 
  const CHARSET_INFO *db_charset;
 
1423
  CHARSET_INFO *db_charset;
1302
1424
  /*
1303
1425
    FIXME: this, and some other variables like 'count_cuted_fields'
1304
1426
    maybe should be statement/cursor local, that is, moved to Statement
1305
1427
    class. With current implementation warnings produced in each prepared
1306
1428
    statement/cursor settle here.
1307
1429
  */
1308
 
  List       <DRIZZLE_ERROR> warn_list;
1309
 
  uint       warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
 
1430
  List       <MYSQL_ERROR> warn_list;
 
1431
  uint       warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
1310
1432
  uint       total_warn_count;
1311
1433
  Diagnostics_area main_da;
1312
1434
 
1337
1459
  uint       tmp_table, global_read_lock;
1338
1460
  uint       server_status,open_options;
1339
1461
  enum enum_thread_type system_thread;
1340
 
  uint32_t       select_number;             //number of select (used for EXPLAIN)
 
1462
  uint       select_number;             //number of select (used for EXPLAIN)
1341
1463
  /* variables.transaction_isolation is reset to this after each commit */
1342
1464
  enum_tx_isolation session_tx_isolation;
1343
1465
  enum_check_fields count_cuted_fields;
1425
1547
  /* Used by the sys_var class to store temporary values */
1426
1548
  union
1427
1549
  {
1428
 
    bool   bool_value;
 
1550
    my_bool   my_bool_value;
1429
1551
    long      long_value;
1430
1552
    ulong     ulong_value;
1431
 
    uint64_t uint64_t_value;
 
1553
    ulonglong ulonglong_value;
1432
1554
  } sys_var_tmp;
1433
1555
  
1434
1556
  struct {
1466
1588
  */
1467
1589
  Lex_input_stream *m_lip;
1468
1590
 
 
1591
  /*
 
1592
    @todo The following is a work around for online backup and the DDL blocker.
 
1593
          It should be removed when the generalized solution is in place.
 
1594
          This is needed to ensure the restore (which uses DDL) is not blocked
 
1595
          when the DDL blocker is engaged.
 
1596
  */
 
1597
  my_bool DDL_exception; // Allow some DDL if there is an exception
 
1598
 
1469
1599
  THD();
1470
1600
  ~THD();
1471
1601
 
1484
1614
  void cleanup(void);
1485
1615
  void cleanup_after_query();
1486
1616
  bool store_globals();
 
1617
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1618
  inline void set_active_vio(Vio* vio)
 
1619
  {
 
1620
    pthread_mutex_lock(&LOCK_delete);
 
1621
    active_vio = vio;
 
1622
    pthread_mutex_unlock(&LOCK_delete);
 
1623
  }
 
1624
  inline void clear_active_vio()
 
1625
  {
 
1626
    pthread_mutex_lock(&LOCK_delete);
 
1627
    active_vio = 0;
 
1628
    pthread_mutex_unlock(&LOCK_delete);
 
1629
  }
 
1630
  void close_active_vio();
 
1631
#endif
1487
1632
  void awake(THD::killed_state state_to_set);
1488
1633
 
 
1634
#ifndef MYSQL_CLIENT
1489
1635
  enum enum_binlog_query_type {
1490
1636
    /*
1491
1637
      The query can be logged row-based or statement-based
1501
1647
      The query represents a change to a table in the "mysql"
1502
1648
      database and is currently mapped to ROW_QUERY_TYPE.
1503
1649
    */
1504
 
    DRIZZLE_QUERY_TYPE,
 
1650
    MYSQL_QUERY_TYPE,
1505
1651
    QUERY_TYPE_COUNT
1506
1652
  };
1507
1653
  
1509
1655
                   char const *query, ulong query_len,
1510
1656
                   bool is_trans, bool suppress_use,
1511
1657
                   THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
 
1658
#endif
1512
1659
 
1513
1660
  /*
1514
1661
    For enter_cond() / exit_cond() to work the mutex must be got before
1558
1705
    start_utime= utime_after_lock= my_micro_time();
1559
1706
  }
1560
1707
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
1561
 
  uint64_t current_utime()  { return my_micro_time(); }
1562
 
  inline uint64_t found_rows(void)
 
1708
  ulonglong current_utime()  { return my_micro_time(); }
 
1709
  inline ulonglong found_rows(void)
1563
1710
  {
1564
1711
    return limit_found_rows;
1565
1712
  }
1577
1724
  }
1578
1725
 
1579
1726
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1580
 
                              const char* str, uint32_t length,
 
1727
                              const char* str, uint length,
1581
1728
                              bool allocate_lex_string);
1582
1729
 
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);
 
1730
  bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
 
1731
                      const char *from, uint from_length,
 
1732
                      CHARSET_INFO *from_cs);
 
1733
 
 
1734
  bool convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs);
 
1735
 
 
1736
  void add_changed_table(TABLE *table);
1590
1737
  void add_changed_table(const char *key, long key_length);
1591
 
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
 
1738
  CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1592
1739
  int send_explain_fields(select_result *result);
1593
1740
  /**
1594
1741
    Clear the current error, if any.
1605
1752
    return;
1606
1753
  }
1607
1754
  inline bool vio_ok() const { return net.vio != 0; }
1608
 
 
 
1755
  /** Return false if connection to client is broken. */
 
1756
  bool vio_is_connected();
1609
1757
  /**
1610
1758
    Mark the current error as fatal. Warning: this does not
1611
1759
    set any error, it sets a property of the error, so must be
1630
1778
    To raise this flag, use my_error().
1631
1779
  */
1632
1780
  inline bool is_error() const { return main_da.is_error(); }
1633
 
  inline const CHARSET_INFO *charset() { return variables.character_set_client; }
 
1781
  inline CHARSET_INFO *charset() { return variables.character_set_client; }
1634
1782
  void update_charset();
1635
1783
 
1636
1784
  void change_item_tree(Item **place, Item *new_value)
1637
1785
  {
 
1786
    /* TODO: check for OOM condition here */
 
1787
    if (!stmt_arena->is_conventional())
 
1788
      nocheck_register_item_tree_change(place, *place, mem_root);
1638
1789
    *place= new_value;
1639
1790
  }
1640
1791
  void nocheck_register_item_tree_change(Item **place, Item *old_value,
1651
1802
    killed_state killed_val; /* to cache the volatile 'killed' */
1652
1803
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1653
1804
  }
1654
 
  void send_kill_message() const;
 
1805
  inline void send_kill_message() const
 
1806
  {
 
1807
    int err= killed_errno();
 
1808
    if (err)
 
1809
      my_message(err, ER(err), MYF(0));
 
1810
  }
1655
1811
  /* return true if we will abort query if we make a warning now */
1656
1812
  inline bool really_abort_on_warning()
1657
1813
  {
1658
1814
    return (abort_on_warning);
1659
1815
  }
1660
1816
  void set_status_var_init();
 
1817
  bool is_context_analysis_only()
 
1818
    { return lex->view_prepare_mode; }
1661
1819
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
1662
1820
  void restore_backup_open_tables_state(Open_tables_state *backup);
 
1821
  void restore_sub_statement_state(Sub_statement_state *backup);
 
1822
  void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
 
1823
  void restore_active_arena(Query_arena *set, Query_arena *backup);
1663
1824
 
1664
1825
  inline void set_current_stmt_binlog_row_based_if_mixed()
1665
1826
  {
1703
1864
 
1704
1865
      Don't reset binlog format for NDB binlog injector thread.
1705
1866
    */
1706
 
    if ((temporary_tables == NULL) && (in_sub_stmt == 0))
 
1867
    if ((temporary_tables == NULL) && (in_sub_stmt == 0) &&
 
1868
        (system_thread != SYSTEM_THREAD_NDBCLUSTER_BINLOG))
1707
1869
    {
1708
1870
      current_stmt_binlog_row_based= 
1709
1871
        test(variables.binlog_format == BINLOG_FORMAT_ROW);
1738
1900
      memcpy(db, new_db, new_db_len+1);
1739
1901
    else
1740
1902
    {
1741
 
      if (db)
1742
 
        free(db);
 
1903
      x_free(db);
1743
1904
      if (new_db)
1744
1905
        db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR));
1745
1906
      else
1770
1931
    allocate memory for a deep copy: current database may be freed after
1771
1932
    a statement is parsed but before it's executed.
1772
1933
  */
1773
 
  bool copy_db_to(char **p_db, size_t *p_db_length);
 
1934
  bool copy_db_to(char **p_db, size_t *p_db_length)
 
1935
  {
 
1936
    if (db == NULL)
 
1937
    {
 
1938
      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
 
1939
      return true;
 
1940
    }
 
1941
    *p_db= strmake(db, db_length);
 
1942
    *p_db_length= db_length;
 
1943
    return false;
 
1944
  }
1774
1945
  thd_scheduler scheduler;
1775
1946
 
1776
1947
public:
1786
1957
    @param level the error level
1787
1958
    @return true if the error is handled
1788
1959
  */
1789
 
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1790
 
                            DRIZZLE_ERROR::enum_warning_level level);
 
1960
  virtual bool handle_error(uint sql_errno, const char *message,
 
1961
                            MYSQL_ERROR::enum_warning_level level);
1791
1962
 
1792
1963
  /**
1793
1964
    Remove the error handler last pushed.
1795
1966
  void pop_internal_handler();
1796
1967
 
1797
1968
private:
1798
 
  const char *proc_info;
1799
 
 
1800
1969
  /** The current internal error handler for this thread, or NULL. */
1801
1970
  Internal_error_handler *m_internal_handler;
1802
1971
  /**
1821
1990
/** A short cut for thd->main_da.set_ok_status(). */
1822
1991
 
1823
1992
inline void
1824
 
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
 
1993
my_ok(THD *thd, ha_rows affected_rows= 0, ulonglong id= 0,
1825
1994
        const char *message= NULL)
1826
1995
{
1827
1996
  thd->main_da.set_ok_status(thd, affected_rows, id, message);
1837
2006
}
1838
2007
 
1839
2008
#define tmp_disable_binlog(A)       \
1840
 
  {uint64_t tmp_disable_binlog__save_options= (A)->options; \
 
2009
  {ulonglong tmp_disable_binlog__save_options= (A)->options; \
1841
2010
  (A)->options&= ~OPTION_BIN_LOG
1842
2011
 
1843
2012
#define reenable_binlog(A)   (A)->options= tmp_disable_binlog__save_options;}
1858
2027
  bool opt_enclosed;
1859
2028
  bool dumpfile;
1860
2029
  ulong skip_lines;
1861
 
  const CHARSET_INFO *cs;
 
2030
  CHARSET_INFO *cs;
1862
2031
  sql_exchange(char *name, bool dumpfile_flag,
1863
2032
               enum_filetype filetype_arg= FILETYPE_CSV);
1864
2033
};
1878
2047
public:
1879
2048
  select_result();
1880
2049
  virtual ~select_result() {};
1881
 
  virtual int prepare(List<Item> &list __attribute__((unused)),
 
2050
  virtual int prepare(List<Item> &list __attribute__((__unused__)),
1882
2051
                      SELECT_LEX_UNIT *u)
1883
2052
  {
1884
2053
    unit= u;
1890
2059
    we need to know number of columns in the result set (if
1891
2060
    there is a result set) apart from sending columns metadata.
1892
2061
  */
1893
 
  virtual uint32_t field_count(List<Item> &fields) const
 
2062
  virtual uint field_count(List<Item> &fields) const
1894
2063
  { return fields.elements; }
1895
 
  virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
 
2064
  virtual bool send_fields(List<Item> &list, uint flags)=0;
1896
2065
  virtual bool send_data(List<Item> &items)=0;
1897
 
  virtual bool initialize_tables (JOIN  __attribute__((unused)) *join=0)
 
2066
  virtual bool initialize_tables (JOIN  __attribute__((__unused__)) *join=0)
1898
2067
  { return 0; }
1899
 
  virtual void send_error(uint32_t errcode,const char *err);
 
2068
  virtual void send_error(uint errcode,const char *err);
1900
2069
  virtual bool send_eof()=0;
1901
2070
  /**
1902
2071
    Check if this query returns a result set and therefore is allowed in
1927
2096
{
1928
2097
public:
1929
2098
  select_result_interceptor() {}              /* Remove gcc warning */
1930
 
  uint32_t field_count(List<Item> &fields __attribute__((unused))) const
 
2099
  uint field_count(List<Item> &fields __attribute__((__unused__))) const
1931
2100
  { return 0; }
1932
 
  bool send_fields(List<Item> &fields __attribute__((unused)),
1933
 
                   uint32_t flag __attribute__((unused))) { return false; }
 
2101
  bool send_fields(List<Item> &fields __attribute__((__unused__)),
 
2102
                   uint flag __attribute__((__unused__))) { return false; }
1934
2103
};
1935
2104
 
1936
2105
 
1943
2112
  bool is_result_set_started;
1944
2113
public:
1945
2114
  select_send() :is_result_set_started(false) {}
1946
 
  bool send_fields(List<Item> &list, uint32_t flags);
 
2115
  bool send_fields(List<Item> &list, uint flags);
1947
2116
  bool send_data(List<Item> &items);
1948
2117
  bool send_eof();
1949
2118
  virtual bool check_simple_select() const { return false; }
1964
2133
  select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1965
2134
  { path[0]=0; }
1966
2135
  ~select_to_file();
1967
 
  void send_error(uint32_t errcode,const char *err);
 
2136
  void send_error(uint errcode,const char *err);
1968
2137
  bool send_eof();
1969
2138
  void cleanup();
1970
2139
};
1980
2149
 
1981
2150
 
1982
2151
class select_export :public select_to_file {
1983
 
  uint32_t field_term_length;
 
2152
  uint field_term_length;
1984
2153
  int field_sep_char,escape_char,line_sep_char;
1985
2154
  int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1986
2155
  /*
2020
2189
 
2021
2190
class select_insert :public select_result_interceptor {
2022
2191
 public:
2023
 
  TableList *table_list;
2024
 
  Table *table;
 
2192
  TABLE_LIST *table_list;
 
2193
  TABLE *table;
2025
2194
  List<Item> *fields;
2026
 
  uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
 
2195
  ulonglong autoinc_value_of_last_inserted_row; // autogenerated or not
2027
2196
  COPY_INFO info;
2028
2197
  bool insert_into_view;
2029
 
  select_insert(TableList *table_list_par,
2030
 
                Table *table_par, List<Item> *fields_par,
 
2198
  select_insert(TABLE_LIST *table_list_par,
 
2199
                TABLE *table_par, List<Item> *fields_par,
2031
2200
                List<Item> *update_fields, List<Item> *update_values,
2032
2201
                enum_duplicates duplic, bool ignore);
2033
2202
  ~select_insert();
2036
2205
  bool send_data(List<Item> &items);
2037
2206
  virtual void store_values(List<Item> &values);
2038
2207
  virtual bool can_rollback_data() { return 0; }
2039
 
  void send_error(uint32_t errcode,const char *err);
 
2208
  void send_error(uint errcode,const char *err);
2040
2209
  bool send_eof();
2041
2210
  void abort();
2042
2211
  /* not implemented: select_insert is never re-used in prepared statements */
2045
2214
 
2046
2215
 
2047
2216
class select_create: public select_insert {
2048
 
  order_st *group;
2049
 
  TableList *create_table;
 
2217
  ORDER *group;
 
2218
  TABLE_LIST *create_table;
2050
2219
  HA_CREATE_INFO *create_info;
2051
 
  TableList *select_tables;
 
2220
  TABLE_LIST *select_tables;
2052
2221
  Alter_info *alter_info;
2053
2222
  Field **field;
2054
2223
  /* lock data for tmp table */
2055
 
  DRIZZLE_LOCK *m_lock;
 
2224
  MYSQL_LOCK *m_lock;
2056
2225
  /* m_lock or thd->extra_lock */
2057
 
  DRIZZLE_LOCK **m_plock;
 
2226
  MYSQL_LOCK **m_plock;
2058
2227
public:
2059
 
  select_create (TableList *table_arg,
 
2228
  select_create (TABLE_LIST *table_arg,
2060
2229
                 HA_CREATE_INFO *create_info_par,
2061
2230
                 Alter_info *alter_info_arg,
2062
2231
                 List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2063
 
                 TableList *select_tables_arg)
 
2232
                 TABLE_LIST *select_tables_arg)
2064
2233
    :select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2065
2234
    create_table(table_arg),
2066
2235
    create_info(create_info_par),
2070
2239
    {}
2071
2240
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2072
2241
 
2073
 
  void binlog_show_create_table(Table **tables, uint32_t count);
 
2242
  void binlog_show_create_table(TABLE **tables, uint count);
2074
2243
  void store_values(List<Item> &values);
2075
 
  void send_error(uint32_t errcode,const char *err);
 
2244
  void send_error(uint errcode,const char *err);
2076
2245
  bool send_eof();
2077
2246
  void abort();
2078
2247
  virtual bool can_rollback_data() { return 1; }
2083
2252
  int prepare2(void) { return 0; }
2084
2253
};
2085
2254
 
2086
 
#include <storage/myisam/myisam.h>
 
2255
#include <myisam.h>
2087
2256
 
2088
2257
/* 
2089
2258
  Param to create temporary tables when doing SELECT:s 
2103
2272
  List<Item> save_copy_funcs;
2104
2273
  Copy_field *copy_field, *copy_field_end;
2105
2274
  Copy_field *save_copy_field, *save_copy_field_end;
2106
 
  unsigned char     *group_buff;
 
2275
  uchar     *group_buff;
2107
2276
  Item      **items_to_copy;                    /* Fields in tmp table */
2108
2277
  MI_COLUMNDEF *recinfo,*start_recinfo;
2109
2278
  KEY *keyinfo;
2110
2279
  ha_rows end_write_records;
2111
2280
  uint  field_count,sum_func_count,func_count;
2112
 
  uint32_t  hidden_field_count;
 
2281
  uint  hidden_field_count;
2113
2282
  uint  group_parts,group_length,group_null_parts;
2114
2283
  uint  quick_group;
2115
2284
  bool  using_indirect_summary_function;
2116
2285
  /* If >0 convert all blob fields to varchar(convert_blob_length) */
2117
 
  uint32_t  convert_blob_length; 
2118
 
  const CHARSET_INFO *table_charset; 
 
2286
  uint  convert_blob_length; 
 
2287
  CHARSET_INFO *table_charset; 
2119
2288
  bool schema_table;
2120
2289
  /*
2121
2290
    True if GROUP BY and its aggregate functions are already computed
2157
2326
{
2158
2327
  TMP_TABLE_PARAM tmp_table_param;
2159
2328
public:
2160
 
  Table *table;
 
2329
  TABLE *table;
2161
2330
 
2162
2331
  select_union() :table(0) {}
2163
2332
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2166
2335
  bool flush();
2167
2336
  void cleanup();
2168
2337
  bool create_result_table(THD *thd, List<Item> *column_types,
2169
 
                           bool is_distinct, uint64_t options,
 
2338
                           bool is_distinct, ulonglong options,
2170
2339
                           const char *alias, bool bit_fields_as_long);
2171
2340
};
2172
2341
 
2224
2393
  Field *field;                         /* Field to sort */
2225
2394
  Item  *item;                          /* Item if not sorting fields */
2226
2395
  uint   length;                        /* Length of sort field */
2227
 
  uint32_t   suffix_length;                 /* Length suffix (0-4) */
 
2396
  uint   suffix_length;                 /* Length suffix (0-4) */
2228
2397
  Item_result result_type;              /* Type of item */
2229
2398
  bool reverse;                         /* if descending sort */
2230
2399
  bool need_strxnfrm;                   /* If we have to use strxnfrm() */
2232
2401
 
2233
2402
 
2234
2403
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 */
 
2404
  uint index;                                   /* 0 or 1 */
 
2405
  uint sort_orders;
 
2406
  uint change_pos;                              /* If sort-fields changed */
2238
2407
  char **buff;
2239
2408
  SORT_FIELD *sortorder;
2240
2409
} SORT_BUFFER;
2294
2463
  Item_result type;
2295
2464
  bool unsigned_flag;
2296
2465
 
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);
 
2466
  double val_real(my_bool *null_value);
 
2467
  longlong val_int(my_bool *null_value) const;
 
2468
  String *val_str(my_bool *null_value, String *str, uint decimals);
 
2469
  my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
2301
2470
  DTCollation collation;
2302
2471
};
2303
2472
 
2313
2482
{
2314
2483
  DYNAMIC_ARRAY file_ptrs;
2315
2484
  ulong max_elements;
2316
 
  uint64_t max_in_memory_size;
 
2485
  ulonglong max_in_memory_size;
2317
2486
  IO_CACHE file;
2318
2487
  TREE tree;
2319
 
  unsigned char *record_pointers;
 
2488
  uchar *record_pointers;
2320
2489
  bool flush();
2321
 
  uint32_t size;
 
2490
  uint size;
2322
2491
 
2323
2492
public:
2324
2493
  ulong elements;
2325
2494
  Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2326
 
         uint32_t size_arg, uint64_t max_in_memory_size_arg);
 
2495
         uint size_arg, ulonglong max_in_memory_size_arg);
2327
2496
  ~Unique();
2328
2497
  ulong elements_in_tree() { return tree.elements_in_tree; }
2329
2498
  inline bool unique_add(void *ptr)
2333
2502
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2334
2503
  }
2335
2504
 
2336
 
  bool get(Table *table);
2337
 
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, 
2338
 
                             uint64_t max_in_memory_size);
2339
 
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, 
2340
 
                                            uint64_t max_in_memory_size)
 
2505
  bool get(TABLE *table);
 
2506
  static double get_use_cost(uint *buffer, uint nkeys, uint key_size, 
 
2507
                             ulonglong max_in_memory_size);
 
2508
  inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size, 
 
2509
                                            ulonglong max_in_memory_size)
2341
2510
  {
2342
 
    register uint64_t max_elems_in_tree=
 
2511
    register ulonglong max_elems_in_tree=
2343
2512
      (1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2344
2513
    return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2345
2514
  }
2347
2516
  void reset();
2348
2517
  bool walk(tree_walk_action action, void *walk_action_arg);
2349
2518
 
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);
 
2519
  friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
 
2520
  friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2352
2521
};
2353
2522
 
2354
2523
 
2355
2524
class multi_delete :public select_result_interceptor
2356
2525
{
2357
 
  TableList *delete_tables, *table_being_deleted;
 
2526
  TABLE_LIST *delete_tables, *table_being_deleted;
2358
2527
  Unique **tempfiles;
2359
2528
  ha_rows deleted, found;
2360
 
  uint32_t num_of_tables;
 
2529
  uint num_of_tables;
2361
2530
  int error;
2362
2531
  bool do_delete;
2363
2532
  /* True if at least one table we delete from is transactional */
2372
2541
  bool error_handled;
2373
2542
 
2374
2543
public:
2375
 
  multi_delete(TableList *dt, uint32_t num_of_tables);
 
2544
  multi_delete(TABLE_LIST *dt, uint num_of_tables);
2376
2545
  ~multi_delete();
2377
2546
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2378
2547
  bool send_data(List<Item> &items);
2379
2548
  bool initialize_tables (JOIN *join);
2380
 
  void send_error(uint32_t errcode,const char *err);
 
2549
  void send_error(uint errcode,const char *err);
2381
2550
  int  do_deletes();
2382
2551
  bool send_eof();
2383
2552
  virtual void abort();
2386
2555
 
2387
2556
class multi_update :public select_result_interceptor
2388
2557
{
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;
 
2558
  TABLE_LIST *all_tables; /* query/update command tables */
 
2559
  TABLE_LIST *leaves;     /* list of leves of join table tree */
 
2560
  TABLE_LIST *update_tables, *table_being_updated;
 
2561
  TABLE **tmp_tables, *main_table, *table_to_update;
2393
2562
  TMP_TABLE_PARAM *tmp_table_param;
2394
2563
  ha_rows updated, found;
2395
2564
  List <Item> *fields, *values;
2396
2565
  List <Item> **fields_for_table, **values_for_table;
2397
 
  uint32_t table_count;
 
2566
  uint table_count;
2398
2567
  /*
2399
2568
   List of tables referenced in the CHECK OPTION condition of
2400
2569
   the updated view excluding the updated table. 
2401
2570
  */
2402
 
  List <Table> unupdated_check_opt_tables;
 
2571
  List <TABLE> unupdated_check_opt_tables;
2403
2572
  Copy_field *copy_field;
2404
2573
  enum enum_duplicates handle_duplicates;
2405
2574
  bool do_update, trans_safe;
2413
2582
  bool error_handled;
2414
2583
 
2415
2584
public:
2416
 
  multi_update(TableList *ut, TableList *leaves_list,
 
2585
  multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2417
2586
               List<Item> *fields, List<Item> *values,
2418
2587
               enum_duplicates handle_duplicates, bool ignore);
2419
2588
  ~multi_update();
2420
2589
  int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2421
2590
  bool send_data(List<Item> &items);
2422
2591
  bool initialize_tables (JOIN *join);
2423
 
  void send_error(uint32_t errcode,const char *err);
 
2592
  void send_error(uint errcode,const char *err);
2424
2593
  int  do_updates();
2425
2594
  bool send_eof();
2426
2595
  virtual void abort();
2430
2599
public:
2431
2600
  LEX_STRING s;
2432
2601
  bool local;
2433
 
  uint32_t offset;
 
2602
  uint offset;
2434
2603
  enum_field_types type;
2435
 
  my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
 
2604
  my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2436
2605
    :s(j), local(i), offset(o), type(t)
2437
2606
  {}
2438
2607
  ~my_var() {}
2466
2635
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2467
2636
                        STATUS_VAR *dec_var);
2468
2637
 
2469
 
#endif /* DRIZZLE_SERVER */
 
2638
#endif /* MYSQL_SERVER */