diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/Makefile.am | 2 | ||||
-rw-r--r-- | sql/field.h | 69 | ||||
-rw-r--r-- | sql/ha_myisam.h | 10 | ||||
-rw-r--r-- | sql/ha_myisammrg.cc | 3 | ||||
-rw-r--r-- | sql/ha_myisammrg.h | 2 | ||||
-rw-r--r-- | sql/handler.cc | 17 | ||||
-rw-r--r-- | sql/item.h | 21 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 15 | ||||
-rw-r--r-- | sql/item_func.h | 23 | ||||
-rw-r--r-- | sql/item_strfunc.h | 26 | ||||
-rw-r--r-- | sql/item_sum.h | 17 | ||||
-rw-r--r-- | sql/item_timefunc.h | 10 | ||||
-rw-r--r-- | sql/item_uniq.h | 2 | ||||
-rw-r--r-- | sql/lex.h | 2 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/procedure.h | 4 | ||||
-rw-r--r-- | sql/slave.h | 34 | ||||
-rw-r--r-- | sql/sql_lex.h | 12 | ||||
-rw-r--r-- | sql/sql_olap.cc | 181 | ||||
-rw-r--r-- | sql/sql_parse.cc | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 19 | ||||
-rw-r--r-- | sql/sql_union.cc | 9 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 27 | ||||
-rw-r--r-- | sql/stacktrace.c | 6 | ||||
-rw-r--r-- | sql/structs.h | 4 | ||||
-rw-r--r-- | sql/table.h | 1 | ||||
-rw-r--r-- | sql/time.cc | 40 |
28 files changed, 468 insertions, 95 deletions
diff --git a/sql/Makefile.am b/sql/Makefile.am index 4e1e78a149c..c1086723337 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -81,7 +81,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \ slave.cc sql_repl.cc sql_union.cc \ mini_client.cc mini_client_errors.c \ - stacktrace.c repl_failsafe.h repl_failsafe.cc + stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS) diff --git a/sql/field.h b/sql/field.h index c795cbac974..69d1fbc826f 100644 --- a/sql/field.h +++ b/sql/field.h @@ -37,20 +37,20 @@ public: static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); } static void operator delete(void *ptr_arg, size_t size) {} /*lint -e715 */ - char *ptr; // Position to field in record - uchar *null_ptr; // Byte where null_bit is - struct st_table *table; // Pointer for table + char *ptr; /* Position to field in record */ + uchar *null_ptr; /* Byte where null_bit is */ + struct st_table *table; /* Pointer for table */ const char *table_name,*field_name; - ulong query_id; // For quick test of used fields - // Field is part of the following keys + ulong query_id; /* For quick test of used fields */ + /* Field is part of the following keys */ key_map key_start,part_of_key,part_of_sortkey; enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL, CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD, BIT_FIELD, TIMESTAMP_FIELD,CAPITALIZE,BLOB_FIELD}; utype unireg_check; - uint32 field_length; // Length of field + uint32 field_length; /* Length of field */ uint16 flags; - uchar null_bit; // Bit used to test null bit + uchar null_bit; /* Bit used to test null bit */ Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg, @@ -90,11 +90,12 @@ public: { return cmp(ptr,(char*) str); } virtual uint decimals() const { return 0; } virtual void sql_type(String &str) const =0; - // Caller beware: sql_type can change str.Ptr, so check - // ptr() to see if it changed if you are using your own buffer - // in str and restore it with set() if needed - - virtual uint size_of() const =0; // For new field + /* + Caller beware: sql_type can change str.Ptr, so check + ptr() to see if it changed if you are using your own buffer + in str and restore it with set() if needed + */ + virtual uint size_of() const =0; /* For new field */ inline bool is_null(uint row_offset=0) { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; } inline bool is_real_null(uint row_offset=0) @@ -186,7 +187,7 @@ public: { return cmp(a,b); } virtual int pack_cmp(const char *b, uint key_length_arg) { return cmp(ptr,b); } - uint offset(); // Should be inline ... + uint offset(); /* Should be inline ... */ void copy_from_tmp(int offset); uint fill_cache_field(struct st_cache_field *copy); virtual bool get_date(TIME *ltime,bool fuzzydate); @@ -211,7 +212,7 @@ public: class Field_num :public Field { public: const uint8 dec; - bool zerofill,unsigned_flag; // Purify cannot handle bit fields + bool zerofill,unsigned_flag; /* Purify cannot handle bit fields */ Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg, @@ -823,7 +824,7 @@ public: class Field_blob :public Field_str { uint packlength; - String value; // For temporaries + String value; /* For temporaries */ bool binary_flag; public: Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, @@ -975,23 +976,23 @@ public: /* -** Create field class for CREATE TABLE + Create field class for CREATE TABLE */ class create_field :public Sql_alloc { public: const char *field_name; - const char *change; // If done with alter table - const char *after; // Put column after this one - Item *def; // Default value + const char *change; /* If done with alter table */ + const char *after; /* Put column after this one */ + Item *def; /* Default value */ enum enum_field_types sql_type; uint32 length; uint decimals,flags,pack_length; Field::utype unireg_check; - TYPELIB *interval; // Which interval to use - Field *field; // For alter table + TYPELIB *interval; /* Which interval to use */ + Field *field; /* For alter table */ - uint8 row,col,sc_length,interval_id; // For rea_create_table + uint8 row,col,sc_length,interval_id; /* For rea_create_table */ uint offset,pack_flag; create_field() :after(0) {} create_field(Field *field, Field *orig_field); @@ -999,7 +1000,7 @@ public: /* -** A class for sending info to the client + A class for sending info to the client */ class Send_field { @@ -1024,14 +1025,14 @@ public: uint from_bit,to_bit; uint from_length,to_length; Field *from_field,*to_field; - String tmp; // For items + String tmp; /* For items */ Copy_field() {} ~Copy_field() {} - void set(Field *to,Field *from,bool save); // Field to field - void set(char *to,Field *from); // Field to string + void set(Field *to,Field *from,bool save); /* Field to field */ + void set(char *to,Field *from); /* Field to string */ void (*do_copy)(Copy_field *); - void (*do_copy2)(Copy_field *); // Used to handle null values + void (*do_copy2)(Copy_field *); /* Used to handle null values */ }; @@ -1052,18 +1053,18 @@ bool test_if_int(const char *str,int length); */ #define FIELDFLAG_DECIMAL 1 -#define FIELDFLAG_BINARY 1 // Shares same flag +#define FIELDFLAG_BINARY 1 /*Shares same flag */ #define FIELDFLAG_NUMBER 2 #define FIELDFLAG_ZEROFILL 4 -#define FIELDFLAG_PACK 120 // Bits used for packing +#define FIELDFLAG_PACK 120 /* Bits used for packing */ #define FIELDFLAG_INTERVAL 256 -#define FIELDFLAG_BITFIELD 512 // mangled with dec! -#define FIELDFLAG_BLOB 1024 // mangled with dec! +#define FIELDFLAG_BITFIELD 512 /* mangled with dec! */ +#define FIELDFLAG_BLOB 1024 /* mangled with dec! */ #define FIELDFLAG_LEFT_FULLSCREEN 8192 #define FIELDFLAG_RIGHT_FULLSCREEN 16384 -#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output -#define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag -#define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql +#define FIELDFLAG_FORMAT_NUMBER 16384 /* predit: ###,,## in output */ +#define FIELDFLAG_SUM ((uint) 32768)/* predit: +#fieldflag */ +#define FIELDFLAG_MAYBE_NULL ((uint) 32768)/* sql */ #define FIELDFLAG_PACK_SHIFT 3 #define FIELDFLAG_DEC_SHIFT 8 #define FIELDFLAG_MAX_DEC 31 diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index 95ebbd87c96..215608f8f0a 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -24,11 +24,11 @@ #include <myisam.h> #include <ft_global.h> -#define HA_RECOVER_NONE 0 // No automatic recover -#define HA_RECOVER_DEFAULT 1 // Automatic recover active -#define HA_RECOVER_BACKUP 2 // Make a backupfile on recover -#define HA_RECOVER_FORCE 4 // Recover even if we loose rows -#define HA_RECOVER_QUICK 8 // Don't check rows in data file +#define HA_RECOVER_NONE 0 /* No automatic recover */ +#define HA_RECOVER_DEFAULT 1 /* Automatic recover active */ +#define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */ +#define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */ +#define HA_RECOVER_QUICK 8 /* Don't check rows in data file */ extern ulong myisam_sort_buffer_size; extern TYPELIB myisam_recover_typelib; diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 2c32fe34285..ee72216baa5 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -75,8 +75,7 @@ int ha_myisammrg::write_row(byte * buf) if (table->time_stamp) update_timestamp(buf+table->time_stamp-1); if (table->next_number_field && buf == table->record[0]) - return (my_errno=HA_ERR_WRONG_COMMAND); - // update_auto_increment(); - [phi] have to check this before allowing it + update_auto_increment(); return myrg_write(file,buf); } diff --git a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h index c93d37ec687..b75d5360097 100644 --- a/sql/ha_myisammrg.h +++ b/sql/ha_myisammrg.h @@ -34,7 +34,7 @@ class ha_myisammrg: public handler const char **bas_ext() const; ulong table_flags() const { - return (HA_REC_NOT_IN_SEQ | HA_READ_RND_SAME | + return (HA_REC_NOT_IN_SEQ | HA_READ_RND_SAME | HA_AUTO_PART_KEY | HA_KEYPOS_TO_RNDPOS | HA_LASTKEY_ORDER | HA_NULL_KEY | HA_BLOB_KEY); } diff --git a/sql/handler.cc b/sql/handler.cc index 7b84c788205..95f238260db 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -630,16 +630,29 @@ longlong handler::get_auto_increment() { longlong nr; int error; + (void) extra(HA_EXTRA_KEYREAD); index_init(table->next_number_index); - error=index_last(table->record[1]); + if (!table->next_number_key_offset) + { // Autoincrement at key-start + error=index_last(table->record[1]); + } + else + { + byte key[MAX_KEY_LENGTH]; + key_copy(key,table,table->next_number_index, + table->next_number_key_offset); + error=index_read(table->record[1], key, table->next_number_key_offset, + HA_READ_PREFIX_LAST); + } + if (error) nr=1; else nr=(longlong) table->next_number_field-> val_int_offset(table->rec_buff_length)+1; - (void) extra(HA_EXTRA_NO_KEYREAD); index_end(); + (void) extra(HA_EXTRA_NO_KEYREAD); return nr; } diff --git a/sql/item.h b/sql/item.h index 910db2fbddc..b31f6cf053a 100644 --- a/sql/item.h +++ b/sql/item.h @@ -82,6 +82,7 @@ public: virtual bool get_date(TIME *ltime,bool fuzzydate); virtual bool get_time(TIME *ltime); virtual bool is_null() { return 0; } + virtual unsigned int size_of () =0; }; @@ -96,6 +97,7 @@ public: :db_name(db_name_par),table_name(table_name_par),field_name(field_name_par) { name = (char*) field_name_par; } const char *full_name() const; + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -136,6 +138,7 @@ public: bool get_date(TIME *ltime,bool fuzzydate); bool get_time(TIME *ltime); bool is_null() { return field->is_null(); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -157,6 +160,7 @@ public: bool basic_const_item() const { return 1; } Item *new_item() { return new Item_null(name); } bool is_null() { return 1; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -186,6 +190,7 @@ public: bool basic_const_item() const { return 1; } Item *new_item() { return new Item_int(name,value,max_length); } void print(String *str); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -200,6 +205,7 @@ public: void make_field(Send_field *field); Item *new_item() { return new Item_uint(name,max_length); } void print(String *str); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -230,6 +236,7 @@ public: void make_field(Send_field *field); bool basic_const_item() const { return 1; } Item *new_item() { return new Item_real(name,value,decimals,max_length); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -241,6 +248,7 @@ public: decimals=NOT_FIXED_DEC; max_length=DBL_DIG+8; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_string :public Item @@ -274,6 +282,7 @@ public: String *const_string() { return &str_value; } inline void append(char *str,uint length) { str_value.append(str,length); } void print(String *str); + virtual unsigned int size_of () { return sizeof(*this);} }; /* for show tables */ @@ -284,6 +293,7 @@ public: Item_datetime(const char *item_name): Item_string(item_name,"",0) { max_length=19;} void make_field(Send_field *field); + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_empty_string :public Item_string @@ -291,6 +301,7 @@ class Item_empty_string :public Item_string public: Item_empty_string(const char *header,uint length) :Item_string("",0) { name=(char*) header; max_length=length;} + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_varbinary :public Item @@ -305,6 +316,7 @@ public: bool save_in_field(Field *field); void make_field(Send_field *field); enum Item_result result_type () const { return INT_RESULT; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -317,6 +329,7 @@ public: Field *tmp_table_field(TABLE *t_arg=(TABLE *)0) { return result_field; } table_map used_tables() const { return 1; } virtual void fix_length_and_dec()=0; + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -366,6 +379,7 @@ public: void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); } enum Item_result result_type () const { return (*ref)->result_type(); } table_map used_tables() const { return (*ref)->used_tables(); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -385,6 +399,7 @@ public: { return ref->save_in_field(field); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -419,6 +434,7 @@ public: table_map used_tables() const { return (table_map) 1L; } bool const_item() const { return 0; } bool is_null() { return null_value; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -429,6 +445,7 @@ public: Item_buff() :null_value(0) {} virtual bool cmp(void)=0; virtual ~Item_buff(); /*line -e1509 */ + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_str_buff :public Item_buff @@ -439,6 +456,7 @@ public: Item_str_buff(Item *arg) :item(arg),value(arg->max_length) {} bool cmp(void); ~Item_str_buff(); // Deallocate String:s + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -449,6 +467,7 @@ class Item_real_buff :public Item_buff public: Item_real_buff(Item *item_par) :item(item_par),value(0.0) {} bool cmp(void); + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_int_buff :public Item_buff @@ -458,6 +477,7 @@ class Item_int_buff :public Item_buff public: Item_int_buff(Item *item_par) :item(item_par),value(0) {} bool cmp(void); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -474,6 +494,7 @@ public: buff= (char*) sql_calloc(length=field->pack_length()); } bool cmp(void); + virtual unsigned int size_of () { return sizeof(*this);} }; extern Item_buff *new_Item_buff(Item *item); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 25d0c239647..8cda0302af5 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -28,6 +28,7 @@ public: Item_bool_func(Item *a) :Item_int_func(a) {} Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {} void fix_length_and_dec() { decimals=0; max_length=1; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_bool_func2 :public Item_int_func @@ -47,6 +48,7 @@ public: bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; } void print(String *str) { Item_func::print_op(str); } bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -80,6 +82,7 @@ public: enum Functype rev_functype() const { return EQUAL_FUNC; } cond_result eq_cmp_result() const { return COND_TRUE; } const char *func_name() const { return "<=>"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -185,6 +188,7 @@ public: ~Item_func_interval() { delete item; } const char *func_name() const { return "interval"; } void update_used_tables(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -199,6 +203,7 @@ public: enum Item_result result_type () const { return cached_result_type; } void fix_length_and_dec(); const char *func_name() const { return "ifnull"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -213,6 +218,7 @@ public: enum Item_result result_type () const { return cached_result_type; } void fix_length_and_dec(); const char *func_name() const { return "if"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -227,6 +233,7 @@ public: enum Item_result result_type () const { return cached_result_type; } void fix_length_and_dec(); const char *func_name() const { return "nullif"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -241,6 +248,7 @@ public: void fix_length_and_dec(); enum Item_result result_type () const { return cached_result_type; } const char *func_name() const { return "coalesce"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_case :public Item_func @@ -261,6 +269,7 @@ public: void print(String *str); bool fix_fields(THD *thd,struct st_table_list *tlist); Item *find_item(String *str); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -422,6 +431,7 @@ class Item_func_in :public Item_int_func enum Functype functype() const { return IN_FUNC; } const char *func_name() const { return " IN "; } void update_used_tables(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -459,6 +469,7 @@ public: } } optimize_type select_optimize() const { return OPTIMIZE_NULL; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_isnotnull :public Item_bool_func @@ -473,6 +484,7 @@ public: } const char *func_name() const { return "isnotnull"; } optimize_type select_optimize() const { return OPTIMIZE_NULL; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_like :public Item_bool_func2 @@ -506,6 +518,7 @@ public: const char *func_name() const { return "like"; } void fix_length_and_dec(); bool fix_fields(THD *thd,struct st_table_list *tlist); + virtual unsigned int size_of () { return sizeof(*this);} }; #ifdef USE_REGEX @@ -525,6 +538,7 @@ public: longlong val_int(); bool fix_fields(THD *thd,struct st_table_list *tlist); const char *func_name() const { return "regex"; } + virtual unsigned int size_of () { return sizeof(*this);} }; #else @@ -561,6 +575,7 @@ public: void print(String *str); void split_sum_func(List<Item> &fields); friend int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds); + virtual unsigned int size_of () { return sizeof(*this);} }; diff --git a/sql/item_func.h b/sql/item_func.h index 5560d3cdb0d..6ecbc04ddf0 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -121,6 +121,7 @@ public: } bool is_null() { (void) val_int(); return null_value; } friend class udf_handler; + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -140,6 +141,7 @@ public: if (!t_arg) return result_field; return new Field_double(max_length, maybe_null, name,t_arg,decimals); } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_num_func :public Item_func @@ -154,6 +156,7 @@ public: enum Item_result result_type () const { return hybrid_type; } void fix_length_and_dec() { fix_num_length_and_dec(); } bool is_null() { (void) val(); return null_value; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -187,6 +190,7 @@ class Item_num_op :public Item_func res= new Field_double(max_length, maybe_null, name, t_arg, decimals); return res; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -459,6 +463,7 @@ public: const char *func_name() const { return truncate ? "truncate" : "round"; } double val(); void fix_length_and_dec(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -494,6 +499,7 @@ class Item_func_units :public Item_real_func double val(); const char *func_name() const { return name; } void fix_length_and_dec() { decimals=NOT_FIXED_DEC; max_length=float_length(decimals); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -510,6 +516,7 @@ public: String *val_str(String *); void fix_length_and_dec(); enum Item_result result_type () const { return cmp_type; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_min :public Item_func_min_max @@ -535,6 +542,7 @@ public: longlong val_int(); const char *func_name() const { return "length"; } void fix_length_and_dec() { max_length=10; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_bit_length :public Item_func_length @@ -553,6 +561,7 @@ public: longlong val_int(); const char *func_name() const { return "char_length"; } void fix_length_and_dec() { max_length=10; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_locate :public Item_int_func @@ -564,6 +573,7 @@ public: const char *func_name() const { return "locate"; } longlong val_int(); void fix_length_and_dec() { maybe_null=0; max_length=11; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -593,6 +603,7 @@ public: const_item_cache&= item->const_item(); with_sum_func= with_sum_func || item->with_sum_func; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -604,6 +615,7 @@ public: longlong val_int(); const char *func_name() const { return "ascii"; } void fix_length_and_dec() { max_length=3; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_ord :public Item_int_func @@ -613,6 +625,7 @@ public: Item_func_ord(Item *a) :Item_int_func(a) {} longlong val_int(); const char *func_name() const { return "ord"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_find_in_set :public Item_int_func @@ -625,6 +638,7 @@ public: longlong val_int(); const char *func_name() const { return "find_in_set"; } void fix_length_and_dec(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -700,6 +714,7 @@ class Item_func_benchmark :public Item_int_func longlong val_int(); const char *func_name() const { return "benchmark"; } void fix_length_and_dec() { max_length=1; maybe_null=0; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -724,6 +739,7 @@ public: return res; } Item_result result_type () const { return udf.result_type(); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -832,6 +848,7 @@ class Item_func_get_lock :public Item_int_func longlong val_int(); const char *func_name() const { return "get_lock"; } void fix_length_and_dec() { max_length=1; maybe_null=1;} + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_release_lock :public Item_int_func @@ -842,6 +859,7 @@ class Item_func_release_lock :public Item_int_func longlong val_int(); const char *func_name() const { return "release_lock"; } void fix_length_and_dec() { max_length=1; maybe_null=1;} + virtual unsigned int size_of () { return sizeof(*this);} }; /* replication functions */ @@ -854,6 +872,7 @@ class Item_master_pos_wait :public Item_int_func longlong val_int(); const char *func_name() const { return "master_pos_wait"; } void fix_length_and_dec() { max_length=1; maybe_null=1;} + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -879,6 +898,7 @@ public: void fix_length_and_dec(); void print(String *str); const char *func_name() const { return "set_user_var"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -903,6 +923,7 @@ public: table_map used_tables() const { return const_var_flag ? 0 : RAND_TABLE_BIT; } bool eq(const Item *item, bool binary_cmp) const; + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -958,6 +979,7 @@ public: bool fix_index(); void init_search(bool no_order); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -1008,4 +1030,5 @@ public: longlong val_int(); const char *func_name() const { return "check_lock"; } void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} + virtual unsigned int size_of () { return sizeof(*this);} }; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 85910f45c77..efff9d93941 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -40,6 +40,7 @@ public: if (!t_arg) return result_field; return (max_length > 255) ? (Field *)new Field_blob(max_length,maybe_null, name,t_arg, binary) : (Field *) new Field_string(max_length,maybe_null, name,t_arg, binary); } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_md5 :public Item_str_func @@ -50,6 +51,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "md5"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_sha :public Item_str_func @@ -89,6 +91,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "concat"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_concat_ws :public Item_str_func @@ -109,6 +112,7 @@ public: || Item_func::fix_fields(thd,tlist)); } const char *func_name() const { return "concat_ws"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_reverse :public Item_str_func @@ -129,6 +133,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "replace"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -141,6 +146,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "insert"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -187,6 +193,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "right"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -199,6 +206,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "substr"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -210,6 +218,7 @@ public: String *val_str(String *); void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "substr_index"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -221,6 +230,7 @@ public: String *val_str(String *); void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "ltrim"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -232,6 +242,7 @@ public: String *val_str(String *); void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "rtrim"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_trim :public Item_str_func @@ -242,6 +253,7 @@ public: String *val_str(String *); void fix_length_and_dec() { max_length= args[0]->max_length; } const char *func_name() const { return "trim"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -253,6 +265,7 @@ public: String *val_str(String *); void fix_length_and_dec() { max_length = 16; } const char *func_name() const { return "password"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_des_encrypt :public Item_str_func @@ -265,6 +278,7 @@ public: void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length+8; } const char *func_name() const { return "des_encrypt"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_des_decrypt :public Item_str_func @@ -276,6 +290,7 @@ public: String *val_str(String *); void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; } const char *func_name() const { return "des_decrypt"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_encrypt :public Item_str_func @@ -286,6 +301,7 @@ public: Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) {} String *val_str(String *); void fix_length_and_dec() { maybe_null=1; max_length = 13; } + virtual unsigned int size_of () { return sizeof(*this);} }; #include "sql_crypt.h" @@ -299,6 +315,7 @@ public: Item_str_func(a),sql_crypt(seed) {} String *val_str(String *); void fix_length_and_dec(); + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_decode :public Item_func_encode @@ -336,6 +353,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "soundex"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -356,6 +374,7 @@ public: void fix_length_and_dec(); void update_used_tables(); const char *func_name() const { return "elt"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -375,6 +394,7 @@ public: void fix_length_and_dec(); void update_used_tables(); const char *func_name() const { return "make_set"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -389,6 +409,7 @@ public: max_length=args[0]->max_length+(args[0]->max_length-args[0]->decimals)/3; } const char *func_name() const { return "format"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -410,6 +431,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "repeat"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -422,6 +444,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "rpad"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -434,6 +457,7 @@ public: String *val_str(String *); void fix_length_and_dec(); const char *func_name() const { return "lpad"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -455,6 +479,7 @@ public: const char *func_name() const { return "hex"; } String *val_str(String *); void fix_length_and_dec() { decimals=0; max_length=args[0]->max_length*2; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -479,6 +504,7 @@ public: const char *func_name() const { return "load_file"; } void fix_length_and_dec() { binary=1; maybe_null=1; max_length=MAX_BLOB_WIDTH;} + virtual unsigned int size_of () { return sizeof(*this);} }; diff --git a/sql/item_sum.h b/sql/item_sum.h index a963799b6a7..8326114629b 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -70,6 +70,7 @@ public: void print(String *str); void fix_num_length_and_dec(); virtual bool setup(THD *thd) {return 0;} + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -84,6 +85,7 @@ public: longlong val_int() { return (longlong) val(); } /* Real as default */ String *val_str(String*str); void reset_field(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -98,6 +100,7 @@ public: double val() { return (double) val_int(); } String *val_str(String*str); enum Item_result result_type () const { return INT_RESULT; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -115,6 +118,7 @@ class Item_sum_sum :public Item_sum_num void reset_field(); void update_field(int offset); const char *func_name() const { return "sum"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -137,6 +141,7 @@ class Item_sum_count :public Item_sum_int void reset_field(); void update_field(int offset); const char *func_name() const { return "count"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -188,6 +193,7 @@ class Item_sum_count_distinct :public Item_sum_int void update_field(int offset) { return ; } // Never called const char *func_name() const { return "count_distinct"; } bool setup(THD *thd); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -207,6 +213,7 @@ public: String *val_str(String*); void make_field(Send_field *field); void fix_length_and_dec() {} + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -228,6 +235,7 @@ class Item_sum_avg :public Item_sum_num Item *result_item(Field *field) { return new Item_avg_field(this); } const char *func_name() const { return "avg"; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_sum_std; @@ -244,6 +252,7 @@ public: bool is_null() { (void) val_int(); return null_value; } void make_field(Send_field *field); void fix_length_and_dec() {} + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_sum_std :public Item_sum_num @@ -264,6 +273,7 @@ class Item_sum_std :public Item_sum_num Item *result_item(Field *field) { return new Item_std_field(this); } const char *func_name() const { return "std"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -306,6 +316,7 @@ class Item_sum_hybrid :public Item_sum void min_max_update_str_field(int offset); void min_max_update_real_field(int offset); void min_max_update_int_field(int offset); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -317,6 +328,7 @@ public: bool add(); const char *func_name() const { return "min"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -328,6 +340,7 @@ public: bool add(); const char *func_name() const { return "max"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -343,6 +356,7 @@ class Item_sum_bit :public Item_sum_int void reset(); longlong val_int(); void reset_field(); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -353,6 +367,7 @@ class Item_sum_or :public Item_sum_bit bool add(); void update_field(int offset); const char *func_name() const { return "bit_or"; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -363,6 +378,7 @@ class Item_sum_and :public Item_sum_bit bool add(); void update_field(int offset); const char *func_name() const { return "bit_and"; } + virtual unsigned int size_of () { return sizeof(*this);} }; /* @@ -393,6 +409,7 @@ public: bool add(); void reset_field() {}; void update_field(int offset_arg) {}; + virtual unsigned int size_of () { return sizeof(*this);} }; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index cc5902b4920..08fbfe25093 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -175,6 +175,7 @@ public: const char *func_name() const { return "weekday"; } enum Item_result result_type () const { return INT_RESULT; } void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_func_dayname :public Item_func_weekday @@ -200,6 +201,7 @@ public: { decimals=0; max_length=10; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -238,6 +240,7 @@ public: if (!t_arg) return result_field; return new Field_date(maybe_null, name, t_arg); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -256,6 +259,7 @@ public: if (!t_arg) return result_field; return new Field_datetime(maybe_null, name, t_arg); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -283,6 +287,7 @@ public: if (!t_arg) return result_field; return new Field_time(maybe_null, name, t_arg); } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -296,6 +301,7 @@ public: const char *func_name() const { return "curdate"; } void fix_length_and_dec(); /* Retrieves curtime */ bool get_date(TIME *res,bool fuzzy_date); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -317,6 +323,7 @@ public: const char *func_name() const { return "now"; } void fix_length_and_dec(); bool get_date(TIME *res,bool fuzzy_date); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -341,6 +348,7 @@ public: const char *func_name() const { return "date_format"; } void fix_length_and_dec(); uint format_length(const String *format); + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -400,6 +408,7 @@ public: double val() { return (double) val_int(); } longlong val_int(); bool get_date(TIME *res,bool fuzzy_date); + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_extract :public Item_int_func @@ -413,6 +422,7 @@ class Item_extract :public Item_int_func longlong val_int(); const char *func_name() const { return "extract"; } void fix_length_and_dec(); + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_typecast :public Item_str_func diff --git a/sql/item_uniq.h b/sql/item_uniq.h index 4be64ecc74a..18f5e5ca45e 100644 --- a/sql/item_uniq.h +++ b/sql/item_uniq.h @@ -29,6 +29,7 @@ public: :Item_real_func(list) {} double val() { return 0.0; } void fix_length_and_dec() { decimals=0; max_length=6; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_sum_unique_users :public Item_sum_num @@ -43,4 +44,5 @@ public: void reset_field() {} void update_field(int offset) {} bool fix_fields(THD *thd,struct st_table_list *tlist) { return 0;} + virtual unsigned int size_of () { return sizeof(*this);} }; diff --git a/sql/lex.h b/sql/lex.h index df80b38950d..9d2411d6a0d 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -97,6 +97,7 @@ static SYMBOL symbols[] = { { "CONSTRAINT", SYM(CONSTRAINT),0,0}, { "CREATE", SYM(CREATE),0,0}, { "CROSS", SYM(CROSS),0,0}, + { "CUBE", SYM(CUBE_SYM),0,0}, { "CURRENT_DATE", SYM(CURDATE),0,0}, { "CURRENT_TIME", SYM(CURTIME),0,0}, { "CURRENT_TIMESTAMP", SYM(NOW_SYM),0,0}, @@ -298,6 +299,7 @@ static SYMBOL symbols[] = { { "RIGHT", SYM(RIGHT),0,0}, { "RLIKE", SYM(REGEXP),0,0}, /* Like in mSQL2 */ { "ROLLBACK", SYM(ROLLBACK_SYM),0,0}, + { "ROLLUP", SYM(ROLLUP_SYM),0,0}, { "ROW", SYM(ROW_SYM),0,0}, { "ROWS", SYM(ROWS_SYM),0,0}, { "SECOND", SYM(SECOND_SYM),0,0}, diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 94a39ebc380..78db1ba2699 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -26,7 +26,7 @@ #include <my_bitmap.h> #ifdef __EMX__ -#undef write // remove pthread.h macro definition for EMX +#undef write /* remove pthread.h macro definition for EMX */ #endif typedef ulong table_map; /* Used for table bits in join */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 96a86a00b48..c1d9f215da0 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2882,7 +2882,7 @@ struct my_option my_long_options[] = "Tells the master that updates to the given database should not be logged tothe binary log", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"bind-address", OPT_BIND_ADDRESS, "Ip address to bind to", - (gptr*) &my_bind_addr, (gptr*) &my_bind_addr, 0, GET_ULONG, REQUIRED_ARG, 0, + (gptr*) &my_bind_addr, (gptr*) &my_bind_addr, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"bootstrap", OPT_BOOTSTRAP, "Used by mysql installation scripts", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, diff --git a/sql/procedure.h b/sql/procedure.h index db0e0b7f9e2..d2600a62e62 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -43,6 +43,7 @@ public: { init_make_field(tmp_field,field_type()); } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_proc_real :public Item_proc @@ -62,6 +63,7 @@ public: double val() { return value; } longlong val_int() { return (longlong) value; } String *val_str(String *s) { s->set(value,decimals); return s; } + virtual unsigned int size_of () { return sizeof(*this);} }; class Item_proc_int :public Item_proc @@ -79,6 +81,7 @@ public: double val() { return (double) value; } longlong val_int() { return value; } String *val_str(String *s) { s->set(value); return s; } + virtual unsigned int size_of () { return sizeof(*this);} }; @@ -98,6 +101,7 @@ public: { return null_value ? (String*) 0 : (String*) &str_value; } + virtual unsigned int size_of () { return sizeof(*this);} }; /* The procedure class definitions */ diff --git a/sql/slave.h b/sql/slave.h index 8657566654a..36849c884e9 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -77,11 +77,11 @@ typedef struct st_relay_log_info cur_log_fd - file descriptor of the current read relay log */ File info_fd,cur_log_fd; - // name of current read relay log + /* name of current read relay log */ char relay_log_name[FN_REFLEN]; - // master log name corresponding to current read position + /* master log name corresponding to current read position */ char master_log_name[FN_REFLEN]; - // original log position of last processed event + /* original log position of last processed event */ volatile my_off_t master_log_pos; /* @@ -92,9 +92,9 @@ typedef struct st_relay_log_info LOG_INFO linfo; IO_CACHE cache_buf,*cur_log; - /*** The following variables are safe to read any time ***/ + /* The following variables are safe to read any time */ - // IO_CACHE of the info file - set only during init or end + /* IO_CACHE of the info file - set only during init or end */ IO_CACHE info_file; /* @@ -117,7 +117,7 @@ typedef struct st_relay_log_info */ pthread_cond_t start_cond, stop_cond, data_cond; - // parent master info structure + /* parent master info structure */ struct st_master_info *mi; /* @@ -153,7 +153,7 @@ typedef struct st_relay_log_info #endif char last_slave_error[MAX_SLAVE_ERRMSG]; - // if not set, the value of other members of the structure are undefined + /* if not set, the value of other members of the structure are undefined */ bool inited; volatile bool abort_slave, slave_running; bool log_pos_current; @@ -189,7 +189,7 @@ typedef struct st_relay_log_info { pending += val; } - // TODO: this probably needs to be fixed + /* TODO: this probably needs to be fixed */ inline void inc_pos(ulonglong val, ulonglong log_pos, bool skip_lock=0) { if (!skip_lock) @@ -254,7 +254,7 @@ typedef struct st_master_info File fd; IO_CACHE file; - // the variables below are needed because we can change masters on the fly + /* the variables below are needed because we can change masters on the fly */ char host[HOSTNAME_LENGTH+1]; char user[USERNAME_LENGTH+1]; char password[HASH_PASSWORD_LENGTH+1]; @@ -262,7 +262,7 @@ typedef struct st_master_info pthread_cond_t data_cond,start_cond,stop_cond; THD *io_thd; MYSQL* mysql; - uint32 file_id; // for 3.23 load data infile + uint32 file_id; /* for 3.23 load data infile */ RELAY_LOG_INFO rli; uint port; uint connect_retry; @@ -270,7 +270,7 @@ typedef struct st_master_info int events_till_abort; #endif bool inited; - bool old_format; // master binlog is in 3.23 format + bool old_format; /* master binlog is in 3.23 format */ volatile bool abort_slave, slave_running; bool ignore_stop_event; @@ -352,18 +352,18 @@ int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock, volatile bool* slave_running, MASTER_INFO* mi); -// If fd is -1, dump to NET +/* If fd is -1, dump to NET */ int mysql_table_dump(THD* thd, const char* db, const char* tbl_name, int fd = -1); -// retrieve non-exitent table from master +/* retrieve non-exitent table from master */ int fetch_master_table(THD* thd, const char* db_name, const char* table_name, MASTER_INFO* mi, MYSQL* mysql); int show_master_info(THD* thd, MASTER_INFO* mi); int show_binlog_info(THD* thd); -// See if the query uses any tables that should not be replicated +/* See if the query uses any tables that should not be replicated */ int tables_ok(THD* thd, TABLE_LIST* tables); /* @@ -382,7 +382,7 @@ int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code); void skip_load_data_infile(NET* net); void slave_print_error(RELAY_LOG_INFO* rli,int err_code, const char* msg, ...); -void end_slave(); // clean up +void end_slave(); /* clean up */ int init_master_info(MASTER_INFO* mi, const char* master_info_fname, const char* slave_info_fname); void end_master_info(MASTER_INFO* mi); @@ -400,7 +400,7 @@ extern bool opt_log_slave_updates ; pthread_handler_decl(handle_slave_io,arg); pthread_handler_decl(handle_slave_sql,arg); extern bool volatile abort_loop; -extern MASTER_INFO main_mi, *active_mi; // active_mi for multi-master +extern MASTER_INFO main_mi, *active_mi; /* active_mi for multi-master */ extern volatile int active_mi_in_use; extern LIST master_list; extern HASH replicate_do_table, replicate_ignore_table; @@ -411,7 +411,7 @@ extern bool table_rules_on; extern int disconnect_slave_event_count, abort_slave_event_count ; -// the master variables are defaults read from my.cnf or command line +/* the master variables are defaults read from my.cnf or command line */ extern uint master_port, master_connect_retry, report_port; extern my_string master_user, master_password, master_host, master_info_file, relay_log_info_file, report_user, report_host, diff --git a/sql/sql_lex.h b/sql/sql_lex.h index fae7eb8e7ff..0c42ce9c6a9 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -92,7 +92,12 @@ typedef struct st_lex_master_info enum sub_select_type { - UNSPECIFIED_TYPE, UNION_TYPE, INTERSECT_TYPE, EXCEPT_TYPE, NOT_A_SELECT + UNSPECIFIED_TYPE, UNION_TYPE, INTERSECT_TYPE, EXCEPT_TYPE, OLAP_TYPE, NOT_A_SELECT +}; + +enum olap_type +{ + NON_EXISTING_ONE, CUBE_TYPE, ROLLUP_TYPE }; /* The state of the lex parsing for selects */ @@ -100,6 +105,7 @@ enum sub_select_type typedef struct st_select_lex { enum sub_select_type linkage; + enum olap_type olap; char *db,*db1,*table1,*db2,*table2; /* For outer join using .. */ Item *where,*having; ha_rows select_limit,offset_limit; @@ -123,7 +129,7 @@ typedef struct st_lex { uint yylineno,yytoklen; /* Simulate lex */ LEX_YYSTYPE yylval; - SELECT_LEX select_lex, *select; + SELECT_LEX select_lex, *select, *last_selects; uchar *ptr,*tok_start,*tok_end,*end_of_query; char *length,*dec,*change,*name; char *backup_dir; /* For RESTORE/BACKUP */ @@ -169,7 +175,7 @@ typedef struct st_lex enum enum_var_type option_type; uint grant,grant_tot_col,which_columns, union_option; thr_lock_type lock_option; - bool drop_primary,drop_if_exists,local_file; + bool drop_primary,drop_if_exists,local_file. olap; bool in_comment,ignore_space,verbose,simple_alter; uint slave_thd_opt; } LEX; diff --git a/sql/sql_olap.cc b/sql/sql_olap.cc new file mode 100644 index 00000000000..d05e891db63 --- /dev/null +++ b/sql/sql_olap.cc @@ -0,0 +1,181 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +/* OLAP implementation by Sinisa Milivojevic <sinisa@mysql.com> */ + +#ifdef __GNUC__ +#pragma implementation // gcc: Class implementation +#endif + +#include "mysql_priv.h" +#include "sql_select.h" + + +/**************************************************************************** + Functions that recursively actually creates new SELECT's + Returns 0 if OK, 1 if error, -1 if error already printed to client +****************************************************************************/ + + +static int make_new_olap_select(LEX *lex, SELECT_LEX *select_lex, List<Item> new_fields) +{ + THD *thd=current_thd; + Item *item, *new_item; + Item_string *constant= new Item_string("ALL",3); + + SELECT_LEX *new_select = (SELECT_LEX *) thd->memdup((char*) select_lex, sizeof(*select_lex)); + if (!new_select) + return 1; + lex->last_selects->next=new_select; + new_select->linkage=OLAP_TYPE; + new_select->olap=NON_EXISTING_ONE; + new_select->group_list.elements=0; + new_select->group_list.first=(byte *)0; + new_select->group_list.next=(byte **)&new_select->group_list.first; + List<Item> privlist; + + List_iterator<Item> list_it(select_lex->item_list); + List_iterator<Item> new_it(new_fields); + + while((item=list_it++)) + { + bool not_found=true; + if (item->type()==Item::FIELD_ITEM) + { + Item_field *iif = (Item_field *)item; + new_it.rewind(); + while ((new_item=new_it++)) + { + if (new_item->type()==Item::FIELD_ITEM && + !strcmp(((Item_field*)new_item)->table_name,iif->table_name) && + !strcmp(((Item_field*)new_item)->field_name,iif->field_name)) + { + not_found=false; + ((Item_field*)new_item)->db_name=iif->db_name; + Item_field *new_one=new Item_field(iif->db_name, iif->table_name, iif->field_name); + privlist.push_back(new_one); + if (add_to_list(new_select->group_list,new_one,1)) + return 1; + break; + } + } + } + if (not_found) + { + if (item->type() == Item::FIELD_ITEM) + privlist.push_back(constant); + else + privlist.push_back((Item*)thd->memdup((char *)item,item->size_of())); + } + } + new_select->item_list=privlist; + + lex->last_selects = new_select; + return 0; +} + +/**************************************************************************** + Functions that recursively creates combinations of queries for OLAP + Returns 0 if OK, 1 if error, -1 if error already printed to client +****************************************************************************/ + +static int olap_combos(List<Item> old_fields, List<Item> new_fields, Item *item, LEX *lex, + SELECT_LEX *select_lex, int position, int selection, int num_fields, + int num_new_fields) +{ + int sl_return = 0; + if(position == num_new_fields) + { + if(item) + new_fields.push_front(item); + sl_return = make_new_olap_select(lex, select_lex, new_fields); + } + else + { + if(item) + new_fields.push_front(item); + while ((num_fields - num_new_fields >= selection - position) && !sl_return) + { + item = old_fields.pop(); + sl_return = olap_combos(old_fields, new_fields, item, lex, select_lex, position+1, ++selection, num_fields, num_new_fields); + } + } + return sl_return; +} + + +/**************************************************************************** + Top level function for converting OLAP clauses to multiple selects + This is also a place where clauses treatment depends on OLAP type + Returns 0 if OK, 1 if error, -1 if error already printed to client +****************************************************************************/ + +int handle_olaps(LEX *lex, SELECT_LEX *select_lex) +{ + List<Item> item_list_copy, new_item_list; + item_list_copy.empty(); + new_item_list.empty(); + int count=select_lex->group_list.elements; + int sl_return=0; + +// a fix for UNION's + for (TABLE_LIST *cursor= (TABLE_LIST *)select_lex->table_list.first; + cursor; + cursor=cursor->next) + { + if (cursor->do_redirect) + { + cursor->table= ((TABLE_LIST*) cursor->table)->table; + cursor->do_redirect=false; + } + } + + lex->last_selects=select_lex; + + for (ORDER *order=(ORDER *)select_lex->group_list.first ; order ; order=order->next) + item_list_copy.push_back(*(order->item)); + + List<Item> all_fields(select_lex->item_list); + + + if (setup_tables((TABLE_LIST *)select_lex->table_list.first) || + setup_fields(lex->thd,(TABLE_LIST *)select_lex->table_list.first,select_lex->item_list,1,&all_fields,1) || + setup_fields(lex->thd,(TABLE_LIST *)select_lex->table_list.first,item_list_copy,1,&all_fields,1)) + return -1; + + if (select_lex->olap == CUBE_TYPE) + { + for( int i=count-1; i>=0 && !sl_return; i--) + sl_return=olap_combos(item_list_copy, new_item_list, (Item *)0, lex, select_lex, 0, 0, count, i); + } + else if (select_lex->olap == ROLLUP_TYPE) + { + for( int i=count-1; i>=0 && !sl_return; i--) + { + Item *item; + item_list_copy.pop(); + List_iterator<Item> it(item_list_copy); + new_item_list.empty(); + while ((item = it++)) + new_item_list.push_front(item); + sl_return=make_new_olap_select(lex, select_lex, new_item_list); + } + } + else + sl_return=1; // impossible + return sl_return; +} diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c8297a584ca..515886a4b2d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2683,6 +2683,7 @@ mysql_init_query(THD *thd) thd->lex.select_lex.table_list.first=0; thd->lex.select_lex.table_list.next= (byte**) &thd->lex.select_lex.table_list.first; thd->lex.select_lex.next=0; + thd->lex.olap=0; thd->fatal_error=0; // Safety thd->last_insert_id_used=thd->query_start_used=thd->insert_id_used=0; thd->sent_row_count=thd->examined_row_count=0; @@ -2699,6 +2700,7 @@ mysql_init_select(LEX *lex) select_lex->offset_limit=0; select_lex->options=0; select_lex->linkage=UNSPECIFIED_TYPE; + select_lex->olap= NON_EXISTING_ONE; lex->exchange = 0; lex->proc_list.first=0; select_lex->order_list.elements=select_lex->group_list.elements=0; @@ -3241,6 +3243,7 @@ static bool create_total_list(THD *thd, LEX *lex, TABLE_LIST **result) for (; aux; aux=next) { TABLE_LIST *cursor; + aux->do_redirect=true; next= aux->next; for (cursor= *result; cursor; cursor=cursor->next) if (!strcmp(cursor->db,aux->db) && diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 89d22e2f595..f9cbab64aad 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -146,7 +146,7 @@ static bool update_sum_func(Item_sum **func); static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, bool distinct, const char *message=NullS); static void describe_info(JOIN *join, const char *info); - +extern int handle_olaps(LEX *lex, SELECT_LEX *select); /* This handles SELECT with and without UNION */ @@ -155,6 +155,23 @@ int handle_select(THD *thd, LEX *lex, select_result *result) { int res; register SELECT_LEX *select_lex = &lex->select_lex; + if (lex->olap) + { + SELECT_LEX *sl, *last_sl; + int returned; + for (sl= &lex->select_lex;sl;sl=sl->next) + { + if (sl->olap != NON_EXISTING_ONE) + { + last_sl=sl->next; + if ((returned=handle_olaps(lex,sl))) + return returned; + lex->last_selects->next=sl=last_sl; + if (!sl) break; + } + } + lex->select = select_lex; + } if (select_lex->next) res=mysql_union(thd,lex,result); else diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 9529b02fecd..88d2f7a1d25 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -49,7 +49,13 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first; cursor; cursor=cursor->next) - cursor->table= ((TABLE_LIST*) cursor->table)->table; + { + if (cursor->do_redirect) + { + cursor->table= ((TABLE_LIST*) cursor->table)->table; + cursor->do_redirect=false; + } + } } /* last_sel now points at the last select where the ORDER BY is stored */ @@ -253,6 +259,7 @@ bool select_union::send_data(List<Item> &values) thd->offset_limit--; return 0; } + fill_record(table->field,values); if ((write_record(table,&info))) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index c9bae82ff04..767a2f67afb 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -110,6 +110,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token COUNT_SYM %token CREATE %token CROSS +%token CUBE_SYM %token DELETE_SYM %token DO_SYM %token DROP @@ -131,6 +132,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token REPLICATION %token RESET_SYM %token ROLLBACK_SYM +%token ROLLUP_SYM %token SELECT_SYM %token SHOW %token SLAVE @@ -2144,7 +2146,7 @@ opt_escape: group_clause: /* empty */ - | GROUP BY group_list; + | GROUP BY group_list olap_opt; group_list: group_list ',' order_ident order_dir @@ -2152,6 +2154,19 @@ group_list: | order_ident order_dir { if (add_group_to_list($1,(bool) $2)) YYABORT; }; +olap_opt: + /* empty */ {} + | WITH CUBE_SYM + { + Lex->olap = true; + Select->olap= CUBE_TYPE; + } + | WITH ROLLUP_SYM + { + Lex->olap = true; + Select->olap= ROLLUP_TYPE; + } + /* Order by statement in select */ @@ -2166,6 +2181,8 @@ order_clause: LEX *lex=Lex; if (lex->sql_command == SQLCOM_MULTI_UPDATE) YYABORT; + if (lex->olap) + YYABORT; lex->select->sort_default=1; } order_list; @@ -2185,12 +2202,18 @@ limit_clause: /* empty */ {} | LIMIT ULONG_NUM { + LEX *lex=Lex; + if (lex->olap) + YYABORT; SELECT_LEX *sel=Select; sel->select_limit= $2; sel->offset_limit= 0L; } | LIMIT ULONG_NUM ',' ULONG_NUM { + LEX *lex=Lex; + if (lex->olap) + YYABORT; SELECT_LEX *sel=Select; sel->select_limit= $4; sel->offset_limit= $2; @@ -3005,6 +3028,7 @@ keyword: | COMMIT_SYM {} | COMPRESSED_SYM {} | CONCURRENT {} + | CUBE_SYM {} | DATA_SYM {} | DATETIME {} | DATE_SYM {} @@ -3096,6 +3120,7 @@ keyword: | RESOURCES {} | RESTORE_SYM {} | ROLLBACK_SYM {} + | ROLLUP_SYM {} | ROWS_SYM {} | ROW_FORMAT_SYM {} | ROW_SYM {} diff --git a/sql/stacktrace.c b/sql/stacktrace.c index d86d65f567e..1aba73dda33 100644 --- a/sql/stacktrace.c +++ b/sql/stacktrace.c @@ -145,7 +145,7 @@ terribly wrong...\n"); fprintf(stderr, "Warning: Alpha stacks are difficult -\ will be taking some wild guesses, stack trace may be incorrect or \ terminate abruptly\n"); - // On Alpha, we need to get pc + /* On Alpha, we need to get pc */ __asm __volatile__ ("bsr %0, do_next; do_next: " :"=r"(pc) :"r"(pc)); @@ -210,8 +210,8 @@ resolve it\n"); void write_core(int sig) { signal(sig, SIG_DFL); - if (fork() != 0) exit(1); // Abort main program - // Core will be written at exit + if (fork() != 0) exit(1); /* Abort main program */ + /* Core will be written at exit */ } #else void write_core(int sig) diff --git a/sql/structs.h b/sql/structs.h index c7a1daee513..bd058a08e46 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -50,14 +50,14 @@ typedef struct st_keyfile_info { /* used with ha_info() */ typedef struct st_key_part_info { /* Info about a key part */ Field *field; uint offset; /* offset in record (from 0) */ - uint null_offset; // Offset to null_bit in record + uint null_offset; /* Offset to null_bit in record */ uint16 length; /* Length of key_part */ uint16 store_length; uint16 key_type; uint16 fieldnr; /* Fieldnum in UNIREG */ uint8 key_part_flag; /* 0 or HA_REVERSE_SORT */ uint8 type; - uint8 null_bit; // Position to null_bit + uint8 null_bit; /* Position to null_bit */ } KEY_PART_INFO ; diff --git a/sql/table.h b/sql/table.h index 63b7a9bc2f7..229d41a2df7 100644 --- a/sql/table.h +++ b/sql/table.h @@ -151,6 +151,7 @@ typedef struct st_table_list bool straight; /* optimize with prev table */ bool updating; /* for replicate-do/ignore table */ bool shared; /* Used twice in union */ + bool do_redirect; /* To get the struct in UNION's */ } TABLE_LIST; diff --git a/sql/time.cc b/sql/time.cc index 1597368908d..817469aa096 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -84,7 +84,7 @@ long my_gmt_sec(TIME *t) /* Get difference in days */ int days= t->day - l_time->tm_mday; if (days < -1) - days= 1; // Month has wrapped + days= 1; /* Month has wrapped */ else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) + @@ -100,15 +100,15 @@ long my_gmt_sec(TIME *t) { int days= t->day - l_time->tm_mday; if (days < -1) - days=1; // Month has wrapped + days=1; /* Month has wrapped */ else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+ (long) (60*((int) t->minute - (int) l_time->tm_min))); if (diff == 3600) - tmp+=3600 - t->minute*60 - t->second; // Move to next hour + tmp+=3600 - t->minute*60 - t->second; /* Move to next hour */ else if (diff == -3600) - tmp-=t->minute*60 + t->second; // Move to next hour + tmp-=t->minute*60 + t->second; /* Move to next hour */ } if ((my_time_zone >=0 ? my_time_zone: -my_time_zone) > 3600L*12) my_time_zone=0; /* Wrong date */ @@ -183,7 +183,7 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week, /* Last week of the previous year */ if (!with_year) return 0; - with_year=0; // Don't check the week again + with_year=0; /* Don't check the week again */ (*year)--; first_daynr-= (days=calc_days_in_year(*year)); weekday= (weekday + 53*7- days) % 7; @@ -198,7 +198,7 @@ uint calc_week(TIME *l_time, bool with_year, bool sunday_first_day_of_week, /* Check if we are on the first week of the next year (or week 53) */ weekday= (weekday + calc_days_in_year(*year)) % 7; if (weekday < 4) - { // We are at first week on next year + { /* We are at first week on next year */ (*year)++; return 1; } @@ -434,7 +434,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) DBUG_ENTER("str_to_TIME"); DBUG_PRINT("enter",("str: %.*s",length,str)); - for (; str != end && !isdigit(*str) ; str++) ; // Skip garbage + for (; str != end && !isdigit(*str) ; str++) ; /* Skip garbage */ if (str == end) DBUG_RETURN(TIMESTAMP_NONE); /* @@ -456,18 +456,18 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) } date[i]=tmp_value; if (i == 2 && str != end && *str == 'T') - str++; // ISO8601: CCYYMMDDThhmmss - else if ( i != 5 ) // Skip inter-field delimiters + str++; /* ISO8601: CCYYMMDDThhmmss */ + else if ( i != 5 ) /* Skip inter-field delimiters */ { while (str != end && (ispunct(*str) || isspace(*str))) { - // Only allow space between days and hours + /* Only allow space between days and hours */ if (isspace(*str) && i != 2) DBUG_RETURN(TIMESTAMP_NONE); str++; } } - field_length=1; // Rest fields can only be 2 + field_length=1; /* Rest fields can only be 2 */ } /* Handle second fractions */ if (i == 6 && (uint) (end-str) >= 2 && *str == '.' && isdigit(str[1])) @@ -572,9 +572,9 @@ bool str_to_time(const char *str,uint length,TIME *l_time) /* Check first if this is a full TIMESTAMP */ if (length >= 12) - { // Probably full timestamp + { /* Probably full timestamp */ if (str_to_TIME(str,length,l_time,1) == TIMESTAMP_FULL) - return 0; // Was an ok timestamp + return 0; /* Was an ok timestamp */ } /* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */ @@ -590,19 +590,19 @@ bool str_to_time(const char *str,uint length,TIME *l_time) LINT_INIT(state); found_days=found_hours=0; if ((uint) (end-str) > 1 && (*str == ' ' && isdigit(str[1]))) - { // days ! + { /* days ! */ date[0]=value; - state=1; // Assume next is hours + state=1; /* Assume next is hours */ found_days=1; - str++; // Skip space; + str++; /* Skip space; */ } else if ((end-str) > 1 && *str == ':' && isdigit(str[1])) { - date[0]=0; // Assume we found hours + date[0]=0; /* Assume we found hours */ date[1]=value; state=2; found_hours=1; - str++; // skip ':' + str++; /* skip ':' */ } else { @@ -623,11 +623,11 @@ bool str_to_time(const char *str,uint length,TIME *l_time) date[state++]=value; if (state == 4 || (end-str) < 2 || *str != ':' || !isdigit(str[1])) break; - str++; // Skip ':' + str++; /* Skip ':' */ } if (state != 4) - { // Not HH:MM:SS + { /* Not HH:MM:SS */ /* Fix the date to assume that seconds was given */ if (!found_hours && !found_days) { |