summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2003-09-03 12:07:18 +0200
committerunknown <serg@serg.mylan>2003-09-03 12:07:18 +0200
commitcf578b265a0ec93333d58c850f695916d36155cb (patch)
tree84310e757264951823af695be9ae599473f79f1b /sql
parent93c9f9c69ff12d765b4c119c3eee240db97cbea7 (diff)
parent4a21b30e47cfb2905ac1e6a3e9a220164067b595 (diff)
downloadmariadb-git-cf578b265a0ec93333d58c850f695916d36155cb.tar.gz
merged
include/my_sys.h: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/myisam.result: Auto merged mysql-test/t/innodb.test: Auto merged mysql-test/t/myisam.test: Auto merged sql/ha_myisam.cc: Auto merged sql/handler.h: Auto merged sql/item_create.cc: Auto merged sql/item_create.h: Auto merged sql/item_func.h: Auto merged sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/lex.h: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_yacc.yy: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_myisam.cc8
-rw-r--r--sql/ha_myisam.h1
-rw-r--r--sql/handler.h71
-rw-r--r--sql/item_create.cc21
-rw-r--r--sql/item_create.h2
-rw-r--r--sql/item_func.cc38
-rw-r--r--sql/item_func.h21
-rw-r--r--sql/item_geofunc.h24
-rw-r--r--sql/item_strfunc.cc42
-rw-r--r--sql/item_strfunc.h49
-rw-r--r--sql/lex.h2
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/mysqld.cc11
-rw-r--r--sql/sql_insert.cc4
-rw-r--r--sql/sql_lex.h24
-rw-r--r--sql/sql_parse.cc8
-rw-r--r--sql/sql_select.cc2
-rw-r--r--sql/sql_show.cc6
-rw-r--r--sql/sql_table.cc118
-rw-r--r--sql/sql_yacc.yy43
20 files changed, 313 insertions, 184 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index e8e4798c2b2..a87bed94484 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -236,6 +236,8 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked)
VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0));
if (!table->db_record_offset)
int_table_flags|=HA_REC_NOT_IN_SEQ;
+ if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
+ int_table_flags|=HA_HAS_CHECKSUM;
return (0);
}
@@ -1414,3 +1416,9 @@ int ha_myisam::ft_read(byte * buf)
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
+
+uint ha_myisam::checksum() const
+{
+ return (uint)file->s->state.checksum;
+}
+
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index 8486e25556b..e4e3192af10 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -64,6 +64,7 @@ class ha_myisam: public handler
uint max_keys() const { return MI_MAX_KEY; }
uint max_key_parts() const { return MAX_REF_PARTS; }
uint max_key_length() const { return MI_MAX_KEY_LENGTH; }
+ uint checksum() const;
int open(const char *name, int mode, uint test_if_locked);
int close(void);
diff --git a/sql/handler.h b/sql/handler.h
index b1b5cfb02b0..b74e06c6edf 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -42,38 +42,39 @@
#define HA_ADMIN_INVALID -5
/* Bits in table_flags() to show what database can do */
-#define HA_READ_RND_SAME 1 /* Read RND-record to KEY-record
- (To update with RND-read) */
-#define HA_KEYPOS_TO_RNDPOS 2 /* ha_info gives pos to record */
-#define HA_TABLE_SCAN_ON_INDEX 4 /* No separate data/index file */
-#define HA_REC_NOT_IN_SEQ 8 /* ha_info don't return recnumber;
- It returns a position to ha_r_rnd */
-#define HA_HAS_GEOMETRY 16
-#define HA_NO_INDEX 32 /* No index needed for next/prev */
-#define HA_KEY_READ_WRONG_STR 64 /* keyread returns converted strings */
-#define HA_NULL_KEY 128 /* One can have keys with NULL */
-#define HA_DUPP_POS 256 /* ha_position() gives dupp row */
-#define HA_NO_BLOBS 512 /* Doesn't support blobs */
-#define HA_BLOB_KEY (HA_NO_BLOBS*2) /* key on blob */
-#define HA_AUTO_PART_KEY (HA_BLOB_KEY*2)
-#define HA_REQUIRE_PRIMARY_KEY (HA_AUTO_PART_KEY*2)
-#define HA_NOT_EXACT_COUNT (HA_REQUIRE_PRIMARY_KEY*2)
-#define HA_NO_WRITE_DELAYED (HA_NOT_EXACT_COUNT*2)
-#define HA_PRIMARY_KEY_IN_READ_INDEX (HA_NO_WRITE_DELAYED*2)
-#define HA_DROP_BEFORE_CREATE (HA_PRIMARY_KEY_IN_READ_INDEX*2)
-#define HA_NOT_READ_AFTER_KEY (HA_DROP_BEFORE_CREATE*2)
-#define HA_NOT_DELETE_WITH_CACHE (HA_NOT_READ_AFTER_KEY*2)
-#define HA_NO_TEMP_TABLES (HA_NOT_DELETE_WITH_CACHE*2)
-#define HA_NO_PREFIX_CHAR_KEYS (HA_NO_TEMP_TABLES*2)
-#define HA_CAN_FULLTEXT (HA_NO_PREFIX_CHAR_KEYS*2)
-#define HA_CAN_SQL_HANDLER (HA_CAN_FULLTEXT*2)
-#define HA_NO_AUTO_INCREMENT (HA_CAN_SQL_HANDLER*2)
+#define HA_READ_RND_SAME 1 /* Read RND-record to KEY-record
+ (To update with RND-read) */
+#define HA_KEYPOS_TO_RNDPOS 2 /* ha_info gives pos to record */
+#define HA_TABLE_SCAN_ON_INDEX 4 /* No separate data/index file */
+#define HA_REC_NOT_IN_SEQ 8 /* ha_info don't return recnumber;
+ It returns a position to ha_r_rnd */
+#define HA_HAS_GEOMETRY (1 << 4)
+#define HA_NO_INDEX (1 << 5) /* No index needed for next/prev */
+#define HA_KEY_READ_WRONG_STR (1 << 6) /* keyread returns converted strings */
+#define HA_NULL_KEY (1 << 7) /* One can have keys with NULL */
+#define HA_DUPP_POS (1 << 8) /* ha_position() gives dupp row */
+#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
+#define HA_BLOB_KEY (1 << 10) /* key on blob */
+#define HA_AUTO_PART_KEY (1 << 11)
+#define HA_REQUIRE_PRIMARY_KEY (1 << 12)
+#define HA_NOT_EXACT_COUNT (1 << 13)
+#define HA_NO_WRITE_DELAYED (1 << 14)
+#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
+#define HA_DROP_BEFORE_CREATE (1 << 16)
+#define HA_NOT_READ_AFTER_KEY (1 << 17)
+#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
+#define HA_NO_TEMP_TABLES (1 << 19)
+#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
+#define HA_CAN_FULLTEXT (1 << 21)
+#define HA_CAN_SQL_HANDLER (1 << 22)
+#define HA_NO_AUTO_INCREMENT (1 << 23)
+#define HA_HAS_CHECKSUM (1 << 24)
/*
Next record gives next record according last record read (even
if database is updated after read). Not used at this point.
*/
-#define HA_LASTKEY_ORDER (HA_NO_AUTO_INCREMENT*2)
+#define HA_LASTKEY_ORDER (1 << 25)
/* bits in index_flags(index_number) for what you can do with index */
@@ -306,8 +307,8 @@ public:
virtual bool check_and_repair(THD *thd) {return 1;}
virtual int optimize(THD* thd,HA_CHECK_OPT* check_opt);
virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt);
- virtual int backup(THD* thd, HA_CHECK_OPT* check_opt);
virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);
+ virtual int backup(THD* thd, HA_CHECK_OPT* check_opt);
/*
restore assumes .frm file must exist, and that generate_table() has been
called; It will just copy the data file and run repair.
@@ -325,8 +326,8 @@ public:
virtual char* get_foreign_key_create_info()
{ return(NULL);} /* gets foreign key create string from InnoDB */
virtual void init_table_handle_for_HANDLER()
- { return; } /* prepare InnoDB for HANDLER */
- virtual void free_foreign_key_create_info(char* str) {}
+ { return; } /* prepare InnoDB for HANDLER */
+ virtual void free_foreign_key_create_info(char* str) {}
/* The following can be called without an open handler */
virtual const char *table_type() const =0;
virtual const char **bas_ext() const =0;
@@ -342,6 +343,7 @@ public:
virtual uint max_key_part_length() { return 255; }
virtual uint min_record_length(uint options) const { return 1; }
virtual bool low_byte_first() const { return 1; }
+ virtual uint checksum() const { return 0; }
virtual bool is_crashed() const { return 0; }
virtual bool auto_repair() const { return 0; }
@@ -355,13 +357,12 @@ public:
/* Type of table for caching query */
virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
- /*
- Is query with this cable cachable (have sense only for ASKTRANSACT
+ /*
+ Is query with this table cachable (have sense only for ASKTRANSACT
tables)
*/
- static bool caching_allowed(THD* thd, char* table_key,
+ static bool caching_allowed(THD* thd, char* table_key,
uint key_length, uint8 cahe_type);
-
};
/* Some extern variables used with handlers */
@@ -390,7 +391,7 @@ int ha_delete_table(enum db_type db_type, const char *path);
void ha_drop_database(char* path);
void ha_key_cache(void);
void ha_resize_key_cache(void);
-int ha_start_stmt(THD *thd);
+int ha_start_stmt(THD *thd);
int ha_report_binlog_offset_and_commit(THD *thd, char *log_file_name,
my_off_t end_offset);
int ha_commit_complete(THD *thd);
diff --git a/sql/item_create.cc b/sql/item_create.cc
index e3e3c021a1e..91113039fd1 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -107,14 +107,6 @@ Item *create_func_cot(Item* a)
new Item_func_tan(a));
}
-
-#ifdef HAVE_COMPRESS
-Item *create_func_crc32(Item* a)
-{
- return new Item_func_crc32(a);
-}
-#endif
-
Item *create_func_date_format(Item* a,Item *b)
{
return new Item_func_date_format(a,b,0);
@@ -666,13 +658,10 @@ Item *create_func_point(Item *a, Item *b)
return new Item_func_point(a, b);
}
-#if !defined(HAVE_COMPRESS)
-
-Item *create_func_compress (Item*a __attribute__((unused))){return 0;}
-Item *create_func_uncompress (Item*a __attribute__((unused))){return 0;}
-Item *create_func_uncompressed_length(Item*a __attribute__((unused))){return 0;}
-
-#else
+Item *create_func_crc32(Item* a)
+{
+ return new Item_func_crc32(a);
+}
Item *create_func_compress(Item* a)
{
@@ -689,8 +678,6 @@ Item *create_func_uncompressed_length(Item* a)
return new Item_func_uncompressed_length(a);
}
-#endif
-
Item *create_func_datediff(Item *a, Item *b)
{
return new Item_func_minus(new Item_func_to_days(a),
diff --git a/sql/item_create.h b/sql/item_create.h
index 16c4fccf709..93a0aa5f556 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -33,9 +33,7 @@ Item *create_func_connection_id(void);
Item *create_func_conv(Item* a, Item *b, Item *c);
Item *create_func_cos(Item* a);
Item *create_func_cot(Item* a);
-#ifdef HAVE_COMPRESS
Item *create_func_crc32(Item* a);
-#endif
Item *create_func_date_format(Item* a,Item *b);
Item *create_func_dayname(Item* a);
Item *create_func_dayofmonth(Item* a);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 4bda8ae78cd..ebc5314580c 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -27,22 +27,18 @@
#include <hash.h>
#include <time.h>
#include <ft_global.h>
-#ifdef HAVE_COMPRESS
-#include <zlib.h>
-#endif
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
const char *fname)
{
my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
- c1.collation->name,c1.derivation_name(),
+ c1.collation->name,c1.derivation_name(),
c2.collation->name,c2.derivation_name(),
fname);
}
-
-static void my_coll_agg_error(DTCollation &c1,
+static void my_coll_agg_error(DTCollation &c1,
DTCollation &c2,
DTCollation &c3,
const char *fname)
@@ -1085,36 +1081,6 @@ longlong Item_func_min_max::val_int()
return value;
}
-
-#ifdef HAVE_COMPRESS
-longlong Item_func_crc32::val_int()
-{
- String *res=args[0]->val_str(&value);
- if (!res)
- {
- null_value=1;
- return 0; /* purecov: inspected */
- }
- null_value=0;
- return (longlong) crc32(0L, (Bytef*)res->ptr(), res->length());
-}
-
-
-longlong Item_func_uncompressed_length::val_int()
-{
- String *res= args[0]->val_str(&value);
- if (!res)
- {
- null_value=1;
- return 0; /* purecov: inspected */
- }
- null_value=0;
- if (res->is_empty()) return 0;
- return uint4korr(res->c_ptr()) & 0x3FFFFFFF;
-}
-#endif /* HAVE_COMPRESS */
-
-
longlong Item_func_length::val_int()
{
String *res=args[0]->val_str(&value);
diff --git a/sql/item_func.h b/sql/item_func.h
index 7fedbcf48ee..b83ed1a61ce 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -555,27 +555,6 @@ public:
};
-#ifdef HAVE_COMPRESS
-class Item_func_crc32 :public Item_int_func
-{
- String value;
-public:
- Item_func_crc32(Item *a) :Item_int_func(a) {}
- longlong val_int();
- const char *func_name() const { return "crc32"; }
- void fix_length_and_dec() { max_length=10; }
-};
-class Item_func_uncompressed_length : public Item_int_func
-{
- String value;
-public:
- Item_func_uncompressed_length(Item *a):Item_int_func(a){}
- longlong val_int();
- const char *func_name() const{return "uncompressed_length";}
- void fix_length_and_dec() { max_length=10; }
-};
-#endif
-
class Item_func_length :public Item_int_func
{
String value;
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h
index d86914eb6c5..79e45cca26f 100644
--- a/sql/item_geofunc.h
+++ b/sql/item_geofunc.h
@@ -167,30 +167,6 @@ public:
const char *func_name() const { return "multipoint"; }
};
-#ifdef HAVE_COMPRESS
-
-class Item_func_compress: public Item_str_func
-{
- String buffer;
-public:
- Item_func_compress(Item *a):Item_str_func(a){}
- String *val_str(String *);
- void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
- const char *func_name() const{return "compress";}
-};
-
-class Item_func_uncompress: public Item_str_func
-{
- String buffer;
-public:
- Item_func_uncompress(Item *a): Item_str_func(a){}
- String *val_str(String *);
- void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;}
- const char *func_name() const{return "uncompress";}
-};
-
-#endif
-
/*
Spatial relations
*/
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index b0b9cc01bf1..17df44f2dba 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2554,6 +2554,31 @@ null:
return 0;
}
+longlong Item_func_uncompressed_length::val_int()
+{
+ String *res= args[0]->val_str(&value);
+ if (!res)
+ {
+ null_value=1;
+ return 0; /* purecov: inspected */
+ }
+ null_value=0;
+ if (res->is_empty()) return 0;
+ return uint4korr(res->c_ptr()) & 0x3FFFFFFF;
+}
+
+longlong Item_func_crc32::val_int()
+{
+ String *res=args[0]->val_str(&value);
+ if (!res)
+ {
+ null_value=1;
+ return 0; /* purecov: inspected */
+ }
+ null_value=0;
+ return (longlong) crc32(0L, (uchar*)res->ptr(), res->length());
+}
+
#ifdef HAVE_COMPRESS
#include "zlib.h"
@@ -2581,7 +2606,7 @@ String *Item_func_compress::val_str(String *str)
buffer.realloc((uint32)new_size + 4 + 1);
Byte *body= ((Byte*)buffer.c_ptr()) + 4;
-
+
if ((err= compress(body, &new_size,
(const Bytef*)res->c_ptr(), res->length())) != Z_OK)
{
@@ -2603,7 +2628,7 @@ String *Item_func_compress::val_str(String *str)
}
buffer.length((uint32)new_size + 4);
-
+
return &buffer;
}
@@ -2615,7 +2640,7 @@ String *Item_func_uncompress::val_str(String *str)
ulong new_size= uint4korr(res->c_ptr()) & 0x3FFFFFFF;
int err= Z_OK;
uint code;
-
+
if (new_size > MAX_BLOB_WIDTH)
{
push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
@@ -2624,21 +2649,20 @@ String *Item_func_uncompress::val_str(String *str)
null_value= 0;
return 0;
}
-
+
buffer.realloc((uint32)new_size);
-
- if ((err= uncompress((Byte*)buffer.c_ptr(), &new_size,
+
+ if ((err= uncompress((Byte*)buffer.c_ptr(), &new_size,
((const Bytef*)res->c_ptr())+4,res->length())) == Z_OK)
{
buffer.length((uint32)new_size);
return &buffer;
}
-
- code= err==Z_BUF_ERROR ? ER_ZLIB_Z_BUF_ERROR :
+
+ code= err==Z_BUF_ERROR ? ER_ZLIB_Z_BUF_ERROR :
err==Z_MEM_ERROR ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR;
push_warning(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,code,ER(code));
null_value= 1;
return 0;
}
-
#endif
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index f64a145b136..cd4bee9712d 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -624,9 +624,56 @@ public:
Item_func_collation(Item *a) :Item_str_func(a) {}
String *val_str(String *);
const char *func_name() const { return "collation"; }
- void fix_length_and_dec()
+ void fix_length_and_dec()
{
max_length=40; // should be enough
collation.set(system_charset_info);
};
};
+
+class Item_func_crc32 :public Item_int_func
+{
+ String value;
+public:
+ Item_func_crc32(Item *a) :Item_int_func(a) {}
+ const char *func_name() const { return "crc32"; }
+ void fix_length_and_dec() { max_length=10; }
+ longlong val_int();
+};
+
+class Item_func_uncompressed_length : public Item_int_func
+{
+ String value;
+public:
+ Item_func_uncompressed_length(Item *a):Item_int_func(a){}
+ const char *func_name() const{return "uncompressed_length";}
+ void fix_length_and_dec() { max_length=10; }
+ longlong val_int();
+};
+
+#ifdef HAVE_COMPRESS
+#define ZLIB_DEPENDED_FUNCTION ;
+#else
+#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
+#endif
+
+class Item_func_compress: public Item_str_func
+{
+ String buffer;
+public:
+ Item_func_compress(Item *a):Item_str_func(a){}
+ void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
+ const char *func_name() const{return "compress";}
+ String *val_str(String *) ZLIB_DEPENDED_FUNCTION
+};
+
+class Item_func_uncompress: public Item_str_func
+{
+ String buffer;
+public:
+ Item_func_uncompress(Item *a): Item_str_func(a){}
+ void fix_length_and_dec(){max_length= MAX_BLOB_WIDTH;}
+ const char *func_name() const{return "uncompress";}
+ String *val_str(String *) ZLIB_DEPENDED_FUNCTION
+};
+
diff --git a/sql/lex.h b/sql/lex.h
index 43a29914e43..686ec6f8c1d 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -479,9 +479,7 @@ static SYMBOL sql_functions[] = {
{ "COUNT", SYM(COUNT_SYM),0,0},
{ "COS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cos)},
{ "COT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_cot)},
-#ifdef HAVE_COMPRESS
{ "CRC32", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_crc32)},
-#endif
{ "CROSSES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_crosses)},
{ "CURDATE", SYM(CURDATE),0,0},
{ "CURTIME", SYM(CURTIME),0,0},
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index a5d9ce5bce3..1ceb410e588 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -411,6 +411,8 @@ bool check_global_access(THD *thd, ulong want_access);
int mysql_backup_table(THD* thd, TABLE_LIST* table_list);
int mysql_restore_table(THD* thd, TABLE_LIST* table_list);
+int mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
+ HA_CHECK_OPT* check_opt);
int mysql_check_table(THD* thd, TABLE_LIST* table_list,
HA_CHECK_OPT* check_opt);
int mysql_repair_table(THD* thd, TABLE_LIST* table_list,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 6cb47a10cb0..a32b0c0f6c1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -4453,14 +4453,15 @@ struct show_var_st status_vars[]= {
{"Bytes_received", (char*) &bytes_received, SHOW_LONG},
{"Bytes_sent", (char*) &bytes_sent, SHOW_LONG},
{"Com_admin_commands", (char*) &com_other, SHOW_LONG},
- {"Com_alter_table", (char*) (com_stat+(uint) SQLCOM_ALTER_TABLE),SHOW_LONG},
{"Com_alter_db", (char*) (com_stat+(uint) SQLCOM_ALTER_DB),SHOW_LONG},
+ {"Com_alter_table", (char*) (com_stat+(uint) SQLCOM_ALTER_TABLE),SHOW_LONG},
{"Com_analyze", (char*) (com_stat+(uint) SQLCOM_ANALYZE),SHOW_LONG},
{"Com_backup_table", (char*) (com_stat+(uint) SQLCOM_BACKUP_TABLE),SHOW_LONG},
{"Com_begin", (char*) (com_stat+(uint) SQLCOM_BEGIN),SHOW_LONG},
{"Com_change_db", (char*) (com_stat+(uint) SQLCOM_CHANGE_DB),SHOW_LONG},
{"Com_change_master", (char*) (com_stat+(uint) SQLCOM_CHANGE_MASTER),SHOW_LONG},
{"Com_check", (char*) (com_stat+(uint) SQLCOM_CHECK),SHOW_LONG},
+ {"Com_checksum", (char*) (com_stat+(uint) SQLCOM_CHECKSUM),SHOW_LONG},
{"Com_commit", (char*) (com_stat+(uint) SQLCOM_COMMIT),SHOW_LONG},
{"Com_create_db", (char*) (com_stat+(uint) SQLCOM_CREATE_DB),SHOW_LONG},
{"Com_create_function", (char*) (com_stat+(uint) SQLCOM_CREATE_FUNCTION),SHOW_LONG},
@@ -4473,6 +4474,7 @@ struct show_var_st status_vars[]= {
{"Com_drop_function", (char*) (com_stat+(uint) SQLCOM_DROP_FUNCTION),SHOW_LONG},
{"Com_drop_index", (char*) (com_stat+(uint) SQLCOM_DROP_INDEX),SHOW_LONG},
{"Com_drop_table", (char*) (com_stat+(uint) SQLCOM_DROP_TABLE),SHOW_LONG},
+ {"Com_drop_user", (char*) (com_stat+(uint) SQLCOM_DROP_USER),SHOW_LONG},
{"Com_flush", (char*) (com_stat+(uint) SQLCOM_FLUSH),SHOW_LONG},
{"Com_grant", (char*) (com_stat+(uint) SQLCOM_GRANT),SHOW_LONG},
{"Com_ha_close", (char*) (com_stat+(uint) SQLCOM_HA_CLOSE),SHOW_LONG},
@@ -4487,6 +4489,7 @@ struct show_var_st status_vars[]= {
{"Com_load_master_table", (char*) (com_stat+(uint) SQLCOM_LOAD_MASTER_TABLE),SHOW_LONG},
{"Com_lock_tables", (char*) (com_stat+(uint) SQLCOM_LOCK_TABLES),SHOW_LONG},
{"Com_optimize", (char*) (com_stat+(uint) SQLCOM_OPTIMIZE),SHOW_LONG},
+ {"Com_preload_keys", (char*) (com_stat+(uint) SQLCOM_PRELOAD_KEYS),SHOW_LONG},
{"Com_purge", (char*) (com_stat+(uint) SQLCOM_PURGE),SHOW_LONG},
{"Com_purge_before_date", (char*) (com_stat+(uint) SQLCOM_PURGE_BEFORE),SHOW_LONG},
{"Com_rename_table", (char*) (com_stat+(uint) SQLCOM_RENAME_TABLE),SHOW_LONG},
@@ -4496,13 +4499,15 @@ struct show_var_st status_vars[]= {
{"Com_reset", (char*) (com_stat+(uint) SQLCOM_RESET),SHOW_LONG},
{"Com_restore_table", (char*) (com_stat+(uint) SQLCOM_RESTORE_TABLE),SHOW_LONG},
{"Com_revoke", (char*) (com_stat+(uint) SQLCOM_REVOKE),SHOW_LONG},
+ {"Com_revoke_all", (char*) (com_stat+(uint) SQLCOM_REVOKE_ALL),SHOW_LONG},
{"Com_rollback", (char*) (com_stat+(uint) SQLCOM_ROLLBACK),SHOW_LONG},
{"Com_savepoint", (char*) (com_stat+(uint) SQLCOM_SAVEPOINT),SHOW_LONG},
{"Com_select", (char*) (com_stat+(uint) SQLCOM_SELECT),SHOW_LONG},
{"Com_set_option", (char*) (com_stat+(uint) SQLCOM_SET_OPTION),SHOW_LONG},
- {"Com_show_binlog_events", (char*) (com_stat+(uint) SQLCOM_SHOW_BINLOG_EVENTS),SHOW_LONG},
{"Com_show_binlogs", (char*) (com_stat+(uint) SQLCOM_SHOW_BINLOGS),SHOW_LONG},
+ {"Com_show_binlog_events", (char*) (com_stat+(uint) SQLCOM_SHOW_BINLOG_EVENTS),SHOW_LONG},
{"Com_show_charsets", (char*) (com_stat+(uint) SQLCOM_SHOW_CHARSETS),SHOW_LONG},
+ {"Com_show_collations", (char*) (com_stat+(uint) SQLCOM_SHOW_COLLATIONS),SHOW_LONG},
{"Com_show_column_types", (char*) (com_stat+(uint) SQLCOM_SHOW_COLUMN_TYPES),SHOW_LONG},
{"Com_show_create_table", (char*) (com_stat+(uint) SQLCOM_SHOW_CREATE),SHOW_LONG},
{"Com_show_create_db", (char*) (com_stat+(uint) SQLCOM_SHOW_CREATE_DB),SHOW_LONG},
@@ -4510,6 +4515,7 @@ struct show_var_st status_vars[]= {
{"Com_show_errors", (char*) (com_stat+(uint) SQLCOM_SHOW_ERRORS),SHOW_LONG},
{"Com_show_fields", (char*) (com_stat+(uint) SQLCOM_SHOW_FIELDS),SHOW_LONG},
{"Com_show_grants", (char*) (com_stat+(uint) SQLCOM_SHOW_GRANTS),SHOW_LONG},
+ {"Com_show_innodb_status", (char*) (com_stat+(uint) SQLCOM_SHOW_INNODB_STATUS),SHOW_LONG},
{"Com_show_keys", (char*) (com_stat+(uint) SQLCOM_SHOW_KEYS),SHOW_LONG},
{"Com_show_logs", (char*) (com_stat+(uint) SQLCOM_SHOW_LOGS),SHOW_LONG},
{"Com_show_master_status", (char*) (com_stat+(uint) SQLCOM_SHOW_MASTER_STAT),SHOW_LONG},
@@ -4520,7 +4526,6 @@ struct show_var_st status_vars[]= {
{"Com_show_slave_hosts", (char*) (com_stat+(uint) SQLCOM_SHOW_SLAVE_HOSTS),SHOW_LONG},
{"Com_show_slave_status", (char*) (com_stat+(uint) SQLCOM_SHOW_SLAVE_STAT),SHOW_LONG},
{"Com_show_status", (char*) (com_stat+(uint) SQLCOM_SHOW_STATUS),SHOW_LONG},
- {"Com_show_innodb_status", (char*) (com_stat+(uint) SQLCOM_SHOW_INNODB_STATUS),SHOW_LONG},
{"Com_show_tables", (char*) (com_stat+(uint) SQLCOM_SHOW_TABLES),SHOW_LONG},
{"Com_show_table_types", (char*) (com_stat+(uint) SQLCOM_SHOW_TABLE_TYPES),SHOW_LONG},
{"Com_show_variables", (char*) (com_stat+(uint) SQLCOM_SHOW_VARIABLES),SHOW_LONG},
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 947205949f1..6cc5d25c34e 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -172,7 +172,10 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
else
res= (table == 0);
else
+ {
+ lock_type=TL_WRITE;
res= open_and_lock_tables(thd, table_list);
+ }
}
else
res= open_and_lock_tables(thd, table_list);
@@ -627,6 +630,7 @@ public:
thd.current_tablenr=0;
thd.version=refresh_version;
thd.command=COM_DELAYED_INSERT;
+ thd.lex.current_select= 0; /* for my_message_sql */
bzero((char*) &thd.net,sizeof(thd.net)); // Safety
thd.system_thread=1;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 7c39d2fe776..0f9b5d80f39 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -60,7 +60,7 @@ enum enum_sql_command {
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
SQLCOM_CREATE_FUNCTION, SQLCOM_DROP_FUNCTION,
SQLCOM_REVOKE,SQLCOM_OPTIMIZE, SQLCOM_CHECK, SQLCOM_PRELOAD_KEYS,
- SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
+ SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
SQLCOM_COMMIT, SQLCOM_SAVEPOINT,
SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
@@ -73,7 +73,7 @@ enum enum_sql_command {
SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER, SQLCOM_DO,
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_TABLE_TYPES, SQLCOM_SHOW_PRIVILEGES,
- SQLCOM_HELP, SQLCOM_DROP_USER, SQLCOM_REVOKE_ALL,
+ SQLCOM_HELP, SQLCOM_DROP_USER, SQLCOM_REVOKE_ALL, SQLCOM_CHECKSUM,
/* This should be the last !!! */
SQLCOM_END
@@ -479,15 +479,21 @@ typedef struct st_lex
SELECT_LEX *all_selects_list;
uchar *ptr,*tok_start,*tok_end,*end_of_query;
char *length,*dec,*change,*name;
+ char *help_arg;
char *backup_dir; /* For RESTORE/BACKUP */
char* to_log; /* For PURGE MASTER LOGS TO */
time_t purge_time; /* For PURGE MASTER LOGS BEFORE */
char* x509_subject,*x509_issuer,*ssl_cipher;
char* found_colon; /* For multi queries - next query */
- enum SSL_type ssl_type; /* defined in violite.h */
String *wild;
sql_exchange *exchange;
select_result *result;
+ Item *default_value, *comment;
+ LEX_USER *grant_user;
+ gptr yacc_yyss,yacc_yyvs;
+ THD *thd;
+ CHARSET_INFO *charset;
+ SQL_LIST *gorder_list;
List<key_part_spec> col_list;
List<key_part_spec> ref_list;
@@ -506,11 +512,6 @@ typedef struct st_lex
TYPELIB *interval;
create_field *last_field;
char *savepoint_name; // Transaction savepoint id
- Item *default_value, *comment;
- uint uint_geom_type;
- LEX_USER *grant_user;
- gptr yacc_yyss,yacc_yyvs;
- THD *thd;
udf_func udf;
HA_CHECK_OPT check_opt; // check/repair options
HA_CREATE_INFO create_info;
@@ -519,6 +520,7 @@ typedef struct st_lex
ulong thread_id,type;
enum_sql_command sql_command;
thr_lock_type lock_option;
+ enum SSL_type ssl_type; /* defined in violite.h */
enum my_lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
@@ -526,17 +528,15 @@ typedef struct st_lex
enum ha_rkey_function ha_rkey_mode;
enum enum_enable_or_disable alter_keys_onoff;
enum enum_var_type option_type;
+ uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
uint fk_delete_opt, fk_update_opt, fk_match_option;
uint param_count;
+ uint slave_thd_opt;
bool drop_primary, drop_if_exists, drop_temporary, local_file;
bool in_comment, ignore_space, verbose, simple_alter, no_write_to_binlog;
bool derived_tables, describe;
bool safe_to_cache_query;
- uint slave_thd_opt;
- CHARSET_INFO *charset;
- char *help_arg;
- SQL_LIST *gorder_list;
st_lex() {}
inline void uncacheable()
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 33e96cc2776..6a9e7e455ba 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2285,6 +2285,14 @@ mysql_execute_command(THD *thd)
break;
}
#endif
+ case SQLCOM_CHECKSUM:
+ {
+ if (check_db_used(thd,tables) ||
+ check_table_access(thd, SELECT_ACL | EXTRA_ACL , tables))
+ goto error; /* purecov: inspected */
+ res = mysql_checksum_table(thd, tables, &lex->check_opt);
+ break;
+ }
case SQLCOM_REPAIR:
{
if (check_db_used(thd,tables) ||
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e38cd146265..5d96f6aeee1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2454,7 +2454,7 @@ static void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array)
Constant tables are ignored.
To avoid bad matches, we don't make ref_table_rows less than 100.
*/
- keyuse->ref_table_rows= ~(table_map) 0; // If no ref
+ keyuse->ref_table_rows= ~(ha_rows) 0; // If no ref
if (keyuse->used_tables &
(map= (keyuse->used_tables & ~join->const_table_map &
~OUTER_REF_TABLE_BIT)))
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 9084269f486..7dd2004b664 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -503,6 +503,8 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
item->maybe_null=1;
field_list.push_back(item=new Item_empty_string("Charset",32));
item->maybe_null=1;
+ field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21));
+ item->maybe_null=1;
field_list.push_back(item=new Item_empty_string("Create_options",255));
item->maybe_null=1;
field_list.push_back(item=new Item_empty_string("Comment",80));
@@ -588,6 +590,10 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
}
str= (table->table_charset ? table->table_charset->name : "default");
protocol->store(str, system_charset_info);
+ if (file->table_flags() & HA_HAS_CHECKSUM)
+ protocol->store((ulonglong)file->checksum());
+ else
+ protocol->store_null(); // Checksum
{
char option_buff[350],*ptr;
ptr=option_buff;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 006cec7000f..6ea7003eba6 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -350,10 +350,10 @@ static int sort_keys(KEY *a, KEY *b)
fields List of fields to create
keys List of keys to create
tmp_table Set to 1 if this is an internal temporary table
- (From ALTER TABLE)
+ (From ALTER TABLE)
no_log Don't log the query to binary log.
- DESCRIPTION
+ DESCRIPTION
If one creates a temporary table, this is automaticly opened
no_log is needed for the case of CREATE ... SELECT,
@@ -672,11 +672,11 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
/*
Make SPATIAL to be RTREE by default
SPATIAL only on BLOB or at least BINARY, this
- actually should be replaced by special GEOM type
+ actually should be replaced by special GEOM type
in near future when new frm file is ready
checking for proper key parts number:
*/
-
+
if (key_info->flags == HA_SPATIAL)
{
if (key_info->key_parts != 1)
@@ -699,7 +699,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
MYF(0), "RTREE INDEX");
DBUG_RETURN(-1);
}
-
+
List_iterator<key_part_spec> cols(key->columns);
for (uint column_nr=0 ; (column=cols++) ; column_nr++)
{
@@ -745,9 +745,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
if (!column->length )
{
- /*
+ /*
BAR: 4 is: (Xmin,Xmax,Ymin,Ymax), this is for 2D case
- Lately we'll extend this code to support more dimensions
+ Lately we'll extend this code to support more dimensions
*/
column->length=4*sizeof(double);
}
@@ -798,7 +798,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
}
else if (column->length > length ||
- ((f_is_packed(sql_field->pack_flag) ||
+ ((f_is_packed(sql_field->pack_flag) ||
((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
(key_info->flags & HA_NOSAME))) &&
column->length != length))
@@ -2561,7 +2561,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
delete_count++;
}
else
- found_count++;
+ found_count++;
}
end_read_record(&info);
free_io_cache(from);
@@ -2593,3 +2593,103 @@ copy_data_between_tables(TABLE *from,TABLE *to,
*deleted=delete_count;
DBUG_RETURN(error > 0 ? -1 : 0);
}
+
+int mysql_checksum_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT *check_opt)
+{
+ TABLE_LIST *table;
+ List<Item> field_list;
+ Item *item;
+ Protocol *protocol= thd->protocol;
+ DBUG_ENTER("mysql_admin_table");
+
+ field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
+ item->maybe_null= 1;
+ field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21));
+ item->maybe_null= 1;
+ if (protocol->send_fields(&field_list, 1))
+ DBUG_RETURN(-1);
+
+ for (table = tables; table; table = table->next)
+ {
+ char table_name[NAME_LEN*2+2];
+ char* db = (table->db) ? table->db : thd->db;
+ bool fatal_error=0;
+ TABLE *t;
+ strxmov(table_name,db ? db : "",".",table->real_name,NullS);
+
+ t=table->table = open_ltable(thd, table, TL_READ_NO_INSERT);
+#ifdef EMBEDDED_LIBRARY
+ thd->net.last_errno= 0; // these errors shouldn't get client
+#endif
+
+ protocol->prepare_for_resend();
+ protocol->store(table_name, system_charset_info);
+
+ if (!t)
+ {
+ protocol->store_null();
+ thd->net.last_error[0]=0;
+ }
+ else
+ {
+ t->pos_in_table_list= table;
+
+ if (t->file->table_flags() & HA_HAS_CHECKSUM &&
+ !(check_opt->flags & T_EXTEND))
+ protocol->store((ulonglong)t->file->checksum());
+ else if (!(t->file->table_flags() & HA_HAS_CHECKSUM) &&
+ check_opt->flags & T_QUICK)
+ protocol->store_null();
+ else
+ {
+ /* calculating table's checksum */
+ ha_checksum crc=0;
+ if (t->file->rnd_init(1))
+ protocol->store_null();
+ else
+ {
+ while (!t->file->rnd_next(t->record[0]))
+ {
+ ha_checksum row_crc=0;
+ if (t->record[0] != t->field[0]->ptr)
+ row_crc=my_checksum(row_crc, t->record[0],
+ t->field[0]->ptr - t->record[0]);
+
+ for (uint i=0; i < t->fields; i++ )
+ {
+ Field *f=t->field[i];
+ if (f->type() == FIELD_TYPE_BLOB)
+ {
+ String tmp;
+ f->val_str(&tmp,&tmp);
+ row_crc=my_checksum(row_crc, tmp.ptr(), tmp.length());
+ }
+ else
+ row_crc=my_checksum(row_crc, f->ptr, f->pack_length());
+ }
+
+ crc+=row_crc;
+ }
+ protocol->store((ulonglong)crc);
+ }
+ }
+#ifdef EMBEDDED_LIBRARY
+ thd->net.last_errno= 0; // these errors shouldn't get client
+#endif
+
+ close_thread_tables(thd);
+ table->table=0; // For query cache
+ }
+ if (protocol->write())
+ goto err;
+ }
+
+ send_eof(thd);
+ DBUG_RETURN(0);
+ err:
+ close_thread_tables(thd); // Shouldn't be needed
+ if (table)
+ table->table=0;
+ DBUG_RETURN(-1);
+}
+
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 076af38cf62..43c037d7e8a 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -677,7 +677,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
show describe load alter optimize preload flush
reset purge begin commit rollback savepoint
slave master_def master_defs
- repair restore backup analyze check start
+ repair restore backup analyze check start checksum
field_list field_list_item field_spec kill column_def key_def
preload_list preload_keys
select_item_list select_item values_list no_braces
@@ -735,23 +735,26 @@ verb_clause:
| begin
| change
| check
+ | checksum
| commit
| create
| delete
| describe
| do
| drop
+ | flush
| grant
+ | handler
+ | help
| insert
- | flush
+ | kill
| load
| lock
- | kill
| optimize
| preload
| purge
| rename
- | repair
+ | repair
| replace
| reset
| restore
@@ -760,15 +763,14 @@ verb_clause:
| savepoint
| select
| set
+ | show
| slave
| start
- | show
| truncate
- | handler
| unlock
| update
| use
- | help;
+ ;
/* help */
@@ -1130,7 +1132,7 @@ opt_select_from:
| select_from select_lock_type;
udf_func_type:
- /* empty */ { $$ = UDFTYPE_FUNCTION; }
+ /* empty */ { $$ = UDFTYPE_FUNCTION; }
| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
udf_type:
@@ -1597,7 +1599,7 @@ opt_ident:
opt_component:
/* empty */ { $$.str= 0; $$.length= 0; }
| '.' ident { $$=$2; };
-
+
string_list:
text_string { Lex->interval_list.push_back($1); }
| string_list ',' text_string { Lex->interval_list.push_back($3); };
@@ -1804,6 +1806,22 @@ backup:
Lex->backup_dir = $6.str;
};
+checksum:
+ CHECKSUM_SYM table_or_tables
+ {
+ LEX *lex=Lex;
+ lex->sql_command = SQLCOM_CHECKSUM;
+ }
+ table_list opt_checksum_type
+ {}
+ ;
+
+opt_checksum_type:
+ /* nothing */ { Lex->check_opt.flags= 0; }
+ | QUICK { Lex->check_opt.flags= T_QUICK; }
+ | EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
+ ;
+
repair:
REPAIR opt_no_write_to_binlog table_or_tables
{
@@ -3413,7 +3431,7 @@ do: DO_SYM
*/
drop:
- DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
+ DROP opt_temporary table_or_tables if_exists table_list opt_restrict
{
LEX *lex=Lex;
lex->sql_command = SQLCOM_DROP_TABLE;
@@ -4925,7 +4943,7 @@ grant_privilege_list:
| grant_privilege_list ',' grant_privilege;
grant_privilege:
- SELECT_SYM { Lex->which_columns = SELECT_ACL;} opt_column_list {}
+ SELECT_SYM { Lex->which_columns = SELECT_ACL;} opt_column_list {}
| INSERT { Lex->which_columns = INSERT_ACL;} opt_column_list {}
| UPDATE_SYM { Lex->which_columns = UPDATE_ACL; } opt_column_list {}
| REFERENCES { Lex->which_columns = REFERENCES_ACL;} opt_column_list {}
@@ -5223,7 +5241,7 @@ union_opt:
;
optional_order_or_limit:
- /* Empty */ {}
+ /* Empty */ {}
|
{
THD *thd= YYTHD;
@@ -5318,3 +5336,4 @@ subselect_end:
LEX *lex=Lex;
lex->current_select = lex->current_select->return_after_parsing();
};
+