From 7006b51823cc6c1f69f42f3c1599385414e6c5b4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 7 Apr 2001 00:18:33 +0200 Subject: Preliminary commit of HANDLER syntax (w/o LIMIT or column-list) --- sql/Makefile.am | 2 +- sql/lex.h | 7 ++- sql/mysql_priv.h | 8 +++ sql/sql_base.cc | 6 +- sql/sql_class.cc | 5 +- sql/sql_class.h | 4 +- sql/sql_handler.cc | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/sql_lex.h | 5 +- sql/sql_parse.cc | 19 +++++- sql/sql_yacc.yy | 88 +++++++++++++++++++++++---- 10 files changed, 294 insertions(+), 22 deletions(-) create mode 100644 sql/sql_handler.cc (limited to 'sql') diff --git a/sql/Makefile.am b/sql/Makefile.am index 7ddb88f26ed..5114ff581f7 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -54,7 +54,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h\ lex.h lex_symbol.h sql_acl.h sql_crypt.h md5.h \ log_event.h mini_client.h sql_repl.h slave.h -mysqld_SOURCES = sql_lex.cc \ +mysqld_SOURCES = sql_lex.cc sql_handler.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ thr_malloc.cc item_create.cc \ diff --git a/sql/lex.h b/sql/lex.h index 3b43922e21f..896c9d40be9 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -82,6 +82,7 @@ static SYMBOL symbols[] = { { "CHANGED", SYM(CHANGED),0,0}, { "CHECK", SYM(CHECK_SYM),0,0}, { "CHECKSUM", SYM(CHECKSUM_SYM),0,0}, + { "CLOSE", SYM(CLOSE_SYM),0,0}, { "COLUMN", SYM(COLUMN_SYM),0,0}, { "COLUMNS", SYM(COLUMNS),0,0}, { "COMMENT", SYM(COMMENT_SYM),0,0}, @@ -152,6 +153,7 @@ static SYMBOL symbols[] = { { "GRANTS", SYM(GRANTS),0,0}, { "GROUP", SYM(GROUP),0,0}, { "HAVING", SYM(HAVING),0,0}, + { "HANDLER", SYM(HANDLER_SYM),0,0}, { "HEAP", SYM(HEAP_SYM),0,0}, { "HIGH_PRIORITY", SYM(HIGH_PRIORITY),0,0}, { "HOUR", SYM(HOUR_SYM),0,0}, @@ -184,6 +186,7 @@ static SYMBOL symbols[] = { { "KEY", SYM(KEY_SYM),0,0}, { "KEYS", SYM(KEYS),0,0}, { "KILL", SYM(KILL_SYM),0,0}, + { "LAST", SYM(LAST_SYM),0,0}, { "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0}, { "LEADING", SYM(LEADING),0,0}, { "LEFT", SYM(LEFT),0,0}, @@ -225,11 +228,12 @@ static SYMBOL symbols[] = { { "MYISAM", SYM(MYISAM_SYM),0,0}, { "NATURAL", SYM(NATURAL),0,0}, { "NATIONAL", SYM(NATIONAL_SYM),0,0}, + { "NEXT", SYM(NEXT_SYM),0,0}, { "NCHAR", SYM(NCHAR_SYM),0,0}, - { "NUMERIC", SYM(NUMERIC_SYM),0,0}, { "NO", SYM(NO_SYM),0,0}, { "NOT", SYM(NOT),0,0}, { "NULL", SYM(NULL_SYM),0,0}, + { "NUMERIC", SYM(NUMERIC_SYM),0,0}, { "ON", SYM(ON),0,0}, { "OPEN", SYM(OPEN_SYM),0,0}, { "OPTIMIZE", SYM(OPTIMIZE),0,0}, @@ -244,6 +248,7 @@ static SYMBOL symbols[] = { { "PASSWORD", SYM(PASSWORD),0,0}, { "PURGE", SYM(PURGE),0,0}, { "PRECISION", SYM(PRECISION),0,0}, + { "PREV", SYM(PREV_SYM),0,0}, { "PRIMARY", SYM(PRIMARY_SYM),0,0}, { "PROCEDURE", SYM(PROCEDURE),0,0}, { "PROCESS" , SYM(PROCESS),0,0}, diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 9af7012f0bc..27fc5d02988 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -381,6 +381,12 @@ int mysqld_show_status(THD *thd); int mysqld_show_variables(THD *thd,const char *wild); int mysqld_show(THD *thd, const char *wild, show_var_st *variables); +/* sql_handler.cc */ +int mysql_ha_open(THD *thd, TABLE_LIST *tables); +int mysql_ha_close(THD *thd, TABLE_LIST *tables); +int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes, + char *,List *,enum ha_rkey_function); + /* sql_base.cc */ void set_item_name(Item *item,char *pos,uint length); bool add_field_to_list(char *field_name, enum enum_field_types type, @@ -402,6 +408,8 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find); SQL_SELECT *make_select(TABLE *head, table_map const_tables, table_map read_tables, COND *conds, int *error); Item ** find_item_in_list(Item *item,List &items); +bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name, + List_iterator *it); bool setup_tables(TABLE_LIST *tables); int setup_fields(THD *thd,TABLE_LIST *tables,List &item, bool set_query_id,List *sum_func_list); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 0024e80219b..7eb26e6fb1a 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -34,8 +34,6 @@ HASH open_cache; /* Used by mysql_test */ static int open_unireg_entry(THD *thd,TABLE *entry,const char *db, const char *name, const char *alias, bool locked); -static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name, - List_iterator *it); static void free_cache_entry(TABLE *entry); static void mysql_rm_tmp_tables(void); static key_map get_key_map_from_key_list(TABLE *table, @@ -409,7 +407,7 @@ void close_thread_tables(THD *thd, bool locked) { DBUG_ENTER("close_thread_tables"); - if (thd->locked_tables) + if (thd->locked_tables || thd->manual_open) DBUG_VOID_RETURN; // LOCK TABLES in use TABLE *table,*next; @@ -1807,7 +1805,7 @@ static key_map get_key_map_from_key_list(TABLE *table, ** Returns pointer to last inserted field if ok ****************************************************************************/ -static bool +bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name, List_iterator *it) { diff --git a/sql/sql_class.cc b/sql/sql_class.cc index d4c7f77f94a..85a19d31210 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -76,7 +76,7 @@ static void free_var(user_var_entry *entry) ****************************************************************************/ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), - insert_id_used(0),in_lock_tables(0), + insert_id_used(0),in_lock_tables(0),manual_open(0), global_read_lock(0),bootstrap(0) { host=user=priv_user=db=query=ip=0; @@ -158,9 +158,10 @@ THD::~THD() net_end(&net); } ha_rollback(this); - if (locked_tables) + if (locked_tables || manual_open) { lock=locked_tables; locked_tables=0; + manual_open=0; close_thread_tables(this); } close_temporary_tables(this); diff --git a/sql/sql_class.h b/sql/sql_class.h index 297b6acbad5..1ad7b3b6110 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -24,7 +24,7 @@ class Query_log_event; class Load_log_event; - +enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY }; enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_IGNORE }; enum enum_log_type { LOG_CLOSED, LOG_NORMAL, LOG_NEW, LOG_BIN }; @@ -278,7 +278,7 @@ public: bool slave_thread; bool set_query_id,locked,count_cuted_fields,some_tables_deleted; bool no_errors, allow_sum_func, password, fatal_error; - bool query_start_used,last_insert_id_used,insert_id_used; + bool query_start_used,last_insert_id_used,insert_id_used,manual_open; bool system_thread,in_lock_tables,global_read_lock; bool query_error, bootstrap; bool volatile killed; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc new file mode 100644 index 00000000000..df6734c5fd3 --- /dev/null +++ b/sql/sql_handler.cc @@ -0,0 +1,172 @@ +/* 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 */ + + +/* HANDLER ... commands - direct access to ISAM */ + +#include "mysql_priv.h" +#include "sql_select.h" + +static TABLE *find_table_by_name(THD *thd, char *db, char *table_name); + +int mysql_ha_open(THD *thd, TABLE_LIST *tables) +{ + int err=open_tables(thd,tables); + if (!err) + { + thd->manual_open=1; + send_ok(&thd->net); + } +} + +int mysql_ha_close(THD *thd, TABLE_LIST *tables) +{ + send_ok(&thd->net); + return 0; +} + +int mysql_ha_read(THD *thd, TABLE_LIST *tables, + enum enum_ha_read_modes mode, char *keyname, List *key_expr, + enum ha_rkey_function ha_rkey_mode) +{ + int err; + TABLE *table=find_table_by_name(thd, tables->db, tables->name); + if (!table) + { + my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), + tables->name,"HANDLER"); + // send_error(&thd->net,ER_UNKNOWN_TABLE); + // send_ok(&thd->net); + return -1; + } + tables->table=table; + + int keyno=find_type(keyname, &table->keynames, 1+2)-1; + if (keyno<0) + { + my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), + keyname,tables->name); + return -1; + } + + List list; + list.push_front(new Item_field(NULL,NULL,"*")); + List_iterator it(list); + it++; + + insert_fields(thd,tables,tables->name,&it); + + table->file->index_init(keyno); + + switch(mode) + { + case RFIRST: + err=table->file->index_first(table->record[0]); + break; + case RLAST: + err=table->file->index_last(table->record[0]); + break; + case RNEXT: + err=table->file->index_next(table->record[0]); + break; + case RPREV: + err=table->file->index_prev(table->record[0]); + break; + case RKEY: + { + KEY *keyinfo=table->key_info+keyno; + uint key_len=0, i; + byte *key, *buf; + for (i=0; i < key_expr->elements; i++) + key_len+=keyinfo->key_part[i].store_length; + if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) + { + send_error(&thd->net,ER_OUTOFMEMORY); + exit(-1); + } + List_iterator it_ke(*key_expr); + for (i=0, buf=key; i < key_expr->elements; i++) + { + uint maybe_null= test(keyinfo->key_part[i].null_bit); + store_key_item ski=store_key_item(keyinfo->key_part[i].field, + (char*)buf+maybe_null,maybe_null ? (char*) buf : 0, + keyinfo->key_part[i].length, it_ke++); + ski.copy(); + buf+=keyinfo->key_part[i].store_length; + } + err=table->file->index_read(table->record[0], + key,key_len,ha_rkey_mode); + break; + } + default: + send_error(&thd->net,ER_ILLEGAL_HA); + exit(-1); + } + + if (err && err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) + { + sql_print_error("mysql_ha_read: Got error %d when reading table", + err); + table->file->print_error(err,MYF(0)); + return -1; + } + send_fields(thd,list,1); + if (!err) + { + String *packet = &thd->packet; + Item *item; + packet->length(0); + it.rewind(); + while ((item=it++)) + { + if (item->send(packet)) + { + packet->free(); // Free used + my_error(ER_OUT_OF_RESOURCES,MYF(0)); + return -1; + } + } + my_net_write(&thd->net, (char*)packet->ptr(), packet->length()); + } + send_eof(&thd->net); + return 0; +} + +/************************************************************************** + 2Monty: It could easily happen, that the following service functions are + already defined somewhere in the code, but I failed to find them. + If this is the case, just say a word and I'll use old functions here. +**************************************************************************/ + +/* Note: this function differs from find_locked_table() because we're looking + here for alias, not real table name + */ +static TABLE *find_table_by_name(THD *thd, char *db, char *table_name) +{ + int dblen; + + if (!db || ! *db) db=thd->db; + if (!db || ! *db) db=""; + dblen=strlen(db); + + for (TABLE *table=thd->open_tables; table ; table=table->next) + { + if (!memcmp(table->table_cache_key, db, dblen) && + !my_strcasecmp(table->table_name,table_name)) + return table; + } + return(0); +} diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 10a99f920bd..f505b870d67 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -53,7 +53,8 @@ enum enum_sql_command { SQLCOM_BEGIN, SQLCOM_LOAD_MASTER_TABLE, SQLCOM_CHANGE_MASTER, SQLCOM_RENAME_TABLE, SQLCOM_BACKUP_TABLE, SQLCOM_RESTORE_TABLE, SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_SHOW_BINLOGS, - SQLCOM_SHOW_OPEN_TABLES + SQLCOM_SHOW_OPEN_TABLES, + SQLCOM_HA_OPEN, SQLCOM_HA_CLOSE, SQLCOM_HA_READ }; enum lex_states { STATE_START, STATE_CHAR, STATE_IDENT, @@ -141,6 +142,8 @@ typedef struct st_lex { enum lex_states next_state; enum enum_duplicates duplicates; enum enum_tx_isolation tx_isolation; + enum enum_ha_read_modes ha_read_mode; + enum ha_rkey_function ha_rkey_mode; uint in_sum_expr,grant,grant_tot_col,which_columns, sort_default; thr_lock_type lock_option; bool create_refs,drop_primary,drop_if_exists,local_file; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 5ed17d76dff..0789f2c07bf 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1996,6 +1996,23 @@ mysql_execute_command(void) res = mysql_show_grants(thd,lex->grant_user); } break; + case SQLCOM_HA_OPEN: + if (check_db_used(thd,tables) || check_table_access(thd,SELECT_ACL, tables)) + goto error; + res = mysql_ha_open(thd, tables); + break; + case SQLCOM_HA_CLOSE: + if (check_db_used(thd,tables)) + goto error; + res = mysql_ha_close(thd, tables); + break; + case SQLCOM_HA_READ: + if (check_db_used(thd,tables) || check_table_access(thd,SELECT_ACL, tables)) + goto error; + res = mysql_ha_read(thd, tables, lex->ha_read_mode, + lex->backup_dir, lex->insert_list, lex->ha_rkey_mode); + break; + case SQLCOM_BEGIN: if (end_active_trans(thd)) { @@ -2041,7 +2058,7 @@ mysql_execute_command(void) } thd->proc_info="query end"; // QQ if (res < 0) - send_error(&thd->net,thd->killed ? ER_SERVER_SHUTDOWN : 0); + send_error(&thd->net,thd->killed ? ER_SERVER_SHUTDOWN : 0, 0); error: DBUG_VOID_RETURN; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1196d279e5c..a2de97534b7 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -142,6 +142,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token CASCADE %token CHECKSUM_SYM %token CHECK_SYM +%token CLOSE_SYM %token COMMITTED_SYM %token COLUMNS %token COLUMN_SYM @@ -176,6 +177,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token GREATEST_SYM %token GROUP %token HAVING +%token HANDLER_SYM %token HEAP_SYM %token HEX_NUM %token HIGH_PRIORITY @@ -193,6 +195,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token JOIN_SYM %token KEYS %token KEY_SYM +%token LAST_SYM %token LEADING %token LEAST_SYM %token LEVEL_SYM @@ -220,6 +223,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token NATIONAL_SYM %token NATURAL %token NCHAR_SYM +%token NEXT_SYM %token NOT %token NO_SYM %token NULL_SYM @@ -236,6 +240,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token DUMPFILE %token PACK_KEYS_SYM %token PARTIAL +%token PREV_SYM %token PRIMARY_SYM %token PRIVILEGES %token PROCESS @@ -516,13 +521,13 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); select_item_list select_item values_list no_braces limit_clause delete_limit_clause fields opt_values values procedure_list procedure_list2 procedure_item - when_list2 expr_list2 + when_list2 expr_list2 handler opt_precision opt_ignore opt_column opt_restrict grant revoke set lock unlock string_list field_options field_option field_opt_list opt_binary table_lock_list table_lock varchar references opt_on_delete opt_on_delete_list opt_on_delete_item use opt_delete_options opt_delete_option - opt_outer table_list table opt_option opt_place opt_low_priority + opt_outer table_list table_name opt_option opt_place opt_low_priority opt_attribute opt_attribute_list attribute column_list column_list_id opt_column_list grant_privileges opt_table user_list grant_option grant_privilege grant_privilege_list @@ -530,7 +535,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); equal optional_braces opt_key_definition key_usage_list2 opt_mi_check_type opt_to mi_check_types normal_join table_to_table_list table_to_table opt_table_list opt_as - END_OF_INPUT + handler_read_function handler_rkey_mode END_OF_INPUT %type '-' '+' '*' '/' '%' '(' ')' @@ -579,6 +584,7 @@ verb_clause: | slave | show | truncate + | handler | unlock | update | use @@ -2003,10 +2009,10 @@ drop: table_list: - table - | table_list ',' table + table_name + | table_list ',' table_name -table: +table_name: table_ident { if (!add_table_to_list($1,NULL,1)) YYABORT; } @@ -2039,7 +2045,7 @@ insert2: | insert_table {} insert_table: - table + table_name { Lex->field_list.empty(); Lex->many_values.empty(); @@ -2128,7 +2134,7 @@ values: /* Update rows in a table */ update: - UPDATE_SYM opt_low_priority opt_ignore table SET update_list where_clause delete_limit_clause + UPDATE_SYM opt_low_priority opt_ignore table_name SET update_list where_clause delete_limit_clause { Lex->sql_command = SQLCOM_UPDATE; } update_list: @@ -2155,7 +2161,7 @@ delete: Lex->sql_command= SQLCOM_DELETE; Lex->options=0; Lex->lock_option= current_thd->update_lock_default; } - opt_delete_options FROM table + opt_delete_options FROM table_name where_clause delete_limit_clause @@ -2168,7 +2174,7 @@ opt_delete_option: | LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; } truncate: - TRUNCATE_SYM opt_table_sym table + TRUNCATE_SYM opt_table_sym table_name { Lex->sql_command= SQLCOM_TRUNCATE; Lex->options=0; Lex->lock_option= current_thd->update_lock_default; } @@ -2519,6 +2525,7 @@ keyword: | CHANGED {} | CHECKSUM_SYM {} | CHECK_SYM {} + | CLOSE_SYM {} | COMMENT_SYM {} | COMMIT_SYM {} | COMMITTED_SYM {} @@ -2544,12 +2551,14 @@ keyword: | GEMINI_SYM {} | GLOBAL_SYM {} | HEAP_SYM {} + | HANDLER_SYM {} | HOSTS_SYM {} | HOUR_SYM {} | IDENTIFIED_SYM {} | ISOLATION {} | ISAM_SYM {} | INNOBASE_SYM {} + | LAST_SYM {} | LEVEL_SYM {} | LOCAL_SYM {} | LOGS_SYM {} @@ -2572,10 +2581,12 @@ keyword: | MYISAM_SYM {} | NATIONAL_SYM {} | NCHAR_SYM {} + | NEXT_SYM {} | NO_SYM {} | OPEN_SYM {} | PACK_KEYS_SYM {} | PASSWORD {} + | PREV_SYM {} | PROCESS {} | PROCESSLIST_SYM {} | QUICK {} @@ -2832,6 +2843,63 @@ unlock: UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; } +/* +** Table: direct access to ISAM functions +*/ + +handler: + HANDLER_SYM table_ident OPEN_SYM opt_table_alias + { + Lex->sql_command = SQLCOM_HA_OPEN; + if (!add_table_to_list($2,$4,0)) + YYABORT; + } + | HANDLER_SYM table_ident CLOSE_SYM + { + Lex->sql_command = SQLCOM_HA_CLOSE; + if (!add_table_to_list($2,0,0)) + YYABORT; + } + | HANDLER_SYM table_ident READ_SYM ident handler_read_function + { + Lex->sql_command = SQLCOM_HA_READ; + Lex->backup_dir= $4.str; + if (!add_table_to_list($2,0,0)) + YYABORT; + } + +handler_read_function: + FIRST_SYM + { + Lex->ha_read_mode = RFIRST; + } + | NEXT_SYM + { + Lex->ha_read_mode = RNEXT; + } + | PREV_SYM + { + Lex->ha_read_mode = RPREV; + } + | LAST_SYM + { + Lex->ha_read_mode = RLAST; + } + | handler_rkey_mode + { + Lex->ha_read_mode = RKEY; + if (!(Lex->insert_list = new List_item)) + YYABORT; + } + '(' values ')' { } + +handler_rkey_mode: + EQ { Lex->ha_rkey_mode=HA_READ_KEY_EXACT; } + | GE { Lex->ha_rkey_mode=HA_READ_KEY_OR_NEXT; } + | LE { Lex->ha_rkey_mode=HA_READ_KEY_OR_PREV; } + | GT_SYM {Lex->ha_rkey_mode=HA_READ_AFTER_KEY; } + | LT { Lex->ha_rkey_mode=HA_READ_BEFORE_KEY; } + /* GRANT / REVOKE */ revoke: -- cgit v1.2.1 From cb2fe473f274c87f9adb39438d76edd598ad7771 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 8 Apr 2001 12:56:12 +0200 Subject: This wouldn't ever be pushed mysql-test/t/handler.test: new tests sql/sql_handler.cc: bugfix --- sql/sql_handler.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sql') diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index df6734c5fd3..17d5ea02e82 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -90,6 +90,12 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, KEY *keyinfo=table->key_info+keyno; uint key_len=0, i; byte *key, *buf; + if (key_expr->elements > keyinfo->key_parts) + { + my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), + MYF(0),keyinfo->key_parts); + return -1; + } for (i=0; i < key_expr->elements; i++) key_len+=keyinfo->key_part[i].store_length; if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) -- cgit v1.2.1 From 9ba069761a280bf319664a9229feadb0cd676b22 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Apr 2001 15:37:19 +0200 Subject: This won't be pushed either mysql-test/t/handler.test: LIMIT tests sql/mysql_priv.h: HANDLER ... LIMIT added sql/sql_handler.cc: HANDLER ... LIMIT added sql/sql_parse.cc: HANDLER ... LIMIT added sql/sql_yacc.yy: HANDLER ... LIMIT added --- sql/mysql_priv.h | 2 +- sql/sql_handler.cc | 154 +++++++++++++++++++++++++++++------------------------ sql/sql_parse.cc | 3 +- sql/sql_yacc.yy | 4 +- 4 files changed, 90 insertions(+), 73 deletions(-) (limited to 'sql') diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 27fc5d02988..89bb69f6d92 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -385,7 +385,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables); int mysql_ha_open(THD *thd, TABLE_LIST *tables); int mysql_ha_close(THD *thd, TABLE_LIST *tables); int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes, - char *,List *,enum ha_rkey_function); + char *,List *,enum ha_rkey_function,ha_rows,ha_rows); /* sql_base.cc */ void set_item_name(Item *item,char *pos,uint length); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 17d5ea02e82..0d82fda8844 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -38,9 +38,13 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables) return 0; } +static enum enum_ha_read_modes rkey_to_rnext[]= + { RNEXT, RNEXT, RPREV, RNEXT, RPREV, RNEXT, RPREV }; + int mysql_ha_read(THD *thd, TABLE_LIST *tables, enum enum_ha_read_modes mode, char *keyname, List *key_expr, - enum ha_rkey_function ha_rkey_mode) + enum ha_rkey_function ha_rkey_mode, + ha_rows select_limit,ha_rows offset_limit) { int err; TABLE *table=find_table_by_name(thd, tables->db, tables->name); @@ -71,81 +75,93 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, table->file->index_init(keyno); - switch(mode) + if (select_limit == thd->default_select_limit) select_limit=1; + + select_limit+=offset_limit; + for (uint num_rows=0; num_rows < select_limit; num_rows++) { - case RFIRST: - err=table->file->index_first(table->record[0]); - break; - case RLAST: - err=table->file->index_last(table->record[0]); - break; - case RNEXT: - err=table->file->index_next(table->record[0]); - break; - case RPREV: - err=table->file->index_prev(table->record[0]); - break; - case RKEY: - { - KEY *keyinfo=table->key_info+keyno; - uint key_len=0, i; - byte *key, *buf; - if (key_expr->elements > keyinfo->key_parts) - { - my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), - MYF(0),keyinfo->key_parts); - return -1; - } - for (i=0; i < key_expr->elements; i++) - key_len+=keyinfo->key_part[i].store_length; - if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) - { - send_error(&thd->net,ER_OUTOFMEMORY); - exit(-1); - } - List_iterator it_ke(*key_expr); - for (i=0, buf=key; i < key_expr->elements; i++) + switch(mode) + { + case RFIRST: + err=table->file->index_first(table->record[0]); + mode=RNEXT; + break; + case RLAST: + err=table->file->index_last(table->record[0]); + mode=RPREV; + break; + case RNEXT: + err=table->file->index_next(table->record[0]); + break; + case RPREV: + err=table->file->index_prev(table->record[0]); + break; + case RKEY: { - uint maybe_null= test(keyinfo->key_part[i].null_bit); - store_key_item ski=store_key_item(keyinfo->key_part[i].field, - (char*)buf+maybe_null,maybe_null ? (char*) buf : 0, - keyinfo->key_part[i].length, it_ke++); - ski.copy(); - buf+=keyinfo->key_part[i].store_length; + KEY *keyinfo=table->key_info+keyno; + uint key_len=0, i; + byte *key, *buf; + if (key_expr->elements > keyinfo->key_parts) + { + my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), + MYF(0),keyinfo->key_parts); + return -1; + } + for (i=0; i < key_expr->elements; i++) + key_len+=keyinfo->key_part[i].store_length; + if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) + { + send_error(&thd->net,ER_OUTOFMEMORY); + return -1; + } + List_iterator it_ke(*key_expr); + for (i=0, buf=key; i < key_expr->elements; i++) + { + uint maybe_null= test(keyinfo->key_part[i].null_bit); + store_key_item ski=store_key_item(keyinfo->key_part[i].field, + (char*)buf+maybe_null,maybe_null ? (char*) buf : 0, + keyinfo->key_part[i].length, it_ke++); + ski.copy(); + buf+=keyinfo->key_part[i].store_length; + } + err=table->file->index_read(table->record[0], + key,key_len,ha_rkey_mode); + mode=rkey_to_rnext[(int)ha_rkey_mode]; + break; } - err=table->file->index_read(table->record[0], - key,key_len,ha_rkey_mode); - break; - } - default: - send_error(&thd->net,ER_ILLEGAL_HA); - exit(-1); - } - - if (err && err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) - { - sql_print_error("mysql_ha_read: Got error %d when reading table", - err); - table->file->print_error(err,MYF(0)); - return -1; - } - send_fields(thd,list,1); - if (!err) - { - String *packet = &thd->packet; - Item *item; - packet->length(0); - it.rewind(); - while ((item=it++)) + default: + send_error(&thd->net,ER_ILLEGAL_HA); + return -1; + } + + if (err && err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) + { + sql_print_error("mysql_ha_read: Got error %d when reading table", + err); + table->file->print_error(err,MYF(0)); + return -1; + } + if (num_rows>=offset_limit) { - if (item->send(packet)) + if (num_rows==offset_limit) send_fields(thd,list,1); + if (!err) { - packet->free(); // Free used - my_error(ER_OUT_OF_RESOURCES,MYF(0)); - return -1; + String *packet = &thd->packet; + Item *item; + packet->length(0); + it.rewind(); + while ((item=it++)) + { + if (item->send(packet)) + { + packet->free(); // Free used + my_error(ER_OUT_OF_RESOURCES,MYF(0)); + return -1; + } + } + my_net_write(&thd->net, (char*)packet->ptr(), packet->length()); } } - my_net_write(&thd->net, (char*)packet->ptr(), packet->length()); } send_eof(&thd->net); return 0; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 0789f2c07bf..72f163ec677 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2010,7 +2010,8 @@ mysql_execute_command(void) if (check_db_used(thd,tables) || check_table_access(thd,SELECT_ACL, tables)) goto error; res = mysql_ha_read(thd, tables, lex->ha_read_mode, - lex->backup_dir, lex->insert_list, lex->ha_rkey_mode); + lex->backup_dir, lex->insert_list, lex->ha_rkey_mode, + lex->select_limit, lex->offset_limit); break; case SQLCOM_BEGIN: diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a2de97534b7..9942be1506f 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -201,6 +201,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token LEVEL_SYM %token LEX_HOSTNAME %token LIKE +%token LIMIT %token LINES %token LOCAL_SYM %token LOGS_SYM @@ -312,7 +313,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token FAST_SYM %token FLOAT_SYM %token INT_SYM -%token LIMIT %token LONGBLOB %token LONGTEXT %token MEDIUMBLOB @@ -2860,7 +2860,7 @@ handler: if (!add_table_to_list($2,0,0)) YYABORT; } - | HANDLER_SYM table_ident READ_SYM ident handler_read_function + | HANDLER_SYM table_ident READ_SYM ident handler_read_function limit_clause { Lex->sql_command = SQLCOM_HA_READ; Lex->backup_dir= $4.str; -- cgit v1.2.1 From ce3b58d6c93e2593ec41c8b7bfddc7c7eb1d2c6d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Apr 2001 16:18:44 +0200 Subject: this won't be pushed Docs/manual.texi: HANDLER documented mysql-test/t/handler.test: more tests --- sql/mysql_priv.h | 4 +- sql/sql_base.cc | 2 +- sql/sql_class.cc | 13 +++- sql/sql_class.h | 6 +- sql/sql_handler.cc | 225 +++++++++++++++++++++++++++++++++-------------------- sql/sql_parse.cc | 6 +- sql/sql_yacc.yy | 57 +++++++------- 7 files changed, 185 insertions(+), 128 deletions(-) (limited to 'sql') diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 89bb69f6d92..4a0ec80077f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -384,8 +384,8 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables); /* sql_handler.cc */ int mysql_ha_open(THD *thd, TABLE_LIST *tables); int mysql_ha_close(THD *thd, TABLE_LIST *tables); -int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes, - char *,List *,enum ha_rkey_function,ha_rows,ha_rows); +int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, + List *,enum ha_rkey_function,Item *,ha_rows,ha_rows); /* sql_base.cc */ void set_item_name(Item *item,char *pos,uint length); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 7eb26e6fb1a..35d8749b452 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -407,7 +407,7 @@ void close_thread_tables(THD *thd, bool locked) { DBUG_ENTER("close_thread_tables"); - if (thd->locked_tables || thd->manual_open) + if (thd->locked_tables) DBUG_VOID_RETURN; // LOCK TABLES in use TABLE *table,*next; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 85a19d31210..567f1e1281e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -76,7 +76,7 @@ static void free_var(user_var_entry *entry) ****************************************************************************/ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), - insert_id_used(0),in_lock_tables(0),manual_open(0), + insert_id_used(0),in_lock_tables(0), global_read_lock(0),bootstrap(0) { host=user=priv_user=db=query=ip=0; @@ -85,7 +85,8 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), query_length=col_access=0; query_error=0; next_insert_id=last_insert_id=0; - open_tables=temporary_tables=0; + open_tables=temporary_tables=handler_tables=0; + handler_items=0; tmp_table=0; lock=locked_tables=0; used_tables=0; @@ -158,10 +159,14 @@ THD::~THD() net_end(&net); } ha_rollback(this); - if (locked_tables || manual_open) + if (locked_tables) { lock=locked_tables; locked_tables=0; - manual_open=0; + close_thread_tables(this); + } + if (handler_tables) + { + open_tables=handler_tables; handler_tables=0; close_thread_tables(this); } close_temporary_tables(this); diff --git a/sql/sql_class.h b/sql/sql_class.h index 1ad7b3b6110..e9d5bc82fd3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -231,7 +231,7 @@ public: const char *proc_info; uint client_capabilities,max_packet_length; uint master_access,db_access; - TABLE *open_tables,*temporary_tables; + TABLE *open_tables,*temporary_tables, *handler_tables; MYSQL_LOCK *lock,*locked_tables; ULL *ull; struct st_my_thread_var *mysys_var; @@ -253,7 +253,7 @@ public: #ifdef HAVE_GEMINI_DB struct st_gemini gemini; #endif - Item *free_list; + Item *free_list, *handler_items; CONVERT *convert_set; Field *dupp_field; #ifndef __WIN__ @@ -278,7 +278,7 @@ public: bool slave_thread; bool set_query_id,locked,count_cuted_fields,some_tables_deleted; bool no_errors, allow_sum_func, password, fatal_error; - bool query_start_used,last_insert_id_used,insert_id_used,manual_open; + bool query_start_used,last_insert_id_used,insert_id_used; bool system_thread,in_lock_tables,global_read_lock; bool query_error, bootstrap; bool volatile killed; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 0d82fda8844..9dbfc6f8626 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -17,23 +17,53 @@ /* HANDLER ... commands - direct access to ISAM */ +#include #include "mysql_priv.h" #include "sql_select.h" +/* TODO: + HANDLER blabla OPEN [ AS foobar ] [ (column-list) ] + + the most natural (easiest, fastest) way to do it is to + compute List field_list not in mysql_ha_read + but in mysql_ha_open, and then store it in TABLE structure. + + The problem here is that mysql_parse calls free_item to free all the + items allocated at the end of every query. The workaround would to + keep two item lists per THD - normal free_list and handler_items. + The second is to be freeed only on thread end. mysql_ha_open should + then do { handler_items=concat(handler_items, free_list); free_list=0; } + + But !!! do_cammand calls free_root at the end of every query and frees up + all the sql_alloc'ed memory. It's harder to work around... + */ + +#define HANDLER_TABLES_HACK(thd) { \ + TABLE *tmp=thd->open_tables; \ + thd->open_tables=thd->handler_tables; \ + thd->handler_tables=tmp; } + static TABLE *find_table_by_name(THD *thd, char *db, char *table_name); int mysql_ha_open(THD *thd, TABLE_LIST *tables) { + HANDLER_TABLES_HACK(thd); int err=open_tables(thd,tables); - if (!err) - { - thd->manual_open=1; - send_ok(&thd->net); - } + HANDLER_TABLES_HACK(thd); + if (err) + return -1; + + send_ok(&thd->net); + return 0; } int mysql_ha_close(THD *thd, TABLE_LIST *tables) { + /* Perhaps, we should close table here. + But it's not easy - *tables is a single-linked list, designed + to be closed at all once. + So, why bother ? All the tables will be closed at thread exit. + */ send_ok(&thd->net); return 0; } @@ -43,27 +73,30 @@ static enum enum_ha_read_modes rkey_to_rnext[]= int mysql_ha_read(THD *thd, TABLE_LIST *tables, enum enum_ha_read_modes mode, char *keyname, List *key_expr, - enum ha_rkey_function ha_rkey_mode, + enum ha_rkey_function ha_rkey_mode, Item *cond, ha_rows select_limit,ha_rows offset_limit) { - int err; + int err, keyno=-1; TABLE *table=find_table_by_name(thd, tables->db, tables->name); if (!table) { my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), - tables->name,"HANDLER"); - // send_error(&thd->net,ER_UNKNOWN_TABLE); - // send_ok(&thd->net); + tables->name,"HANDLER"); return -1; } tables->table=table; + + if (cond && cond->fix_fields(thd,tables)) + return -1; - int keyno=find_type(keyname, &table->keynames, 1+2)-1; - if (keyno<0) + if (keyname) { - my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), - keyname,tables->name); - return -1; + if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0) + { + my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), + keyname,tables->name); + return -1; + } } List list; @@ -72,99 +105,121 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, it++; insert_fields(thd,tables,tables->name,&it); - + table->file->index_init(keyno); + + select_limit+=offset_limit; + send_fields(thd,list,1); - if (select_limit == thd->default_select_limit) select_limit=1; + MYSQL_LOCK *lock=mysql_lock_tables(thd,&tables->table,1); - select_limit+=offset_limit; - for (uint num_rows=0; num_rows < select_limit; num_rows++) + for (uint num_rows=0; num_rows < select_limit; ) { switch(mode) { case RFIRST: - err=table->file->index_first(table->record[0]); - mode=RNEXT; - break; + err=keyname ? + table->file->index_first(table->record[0]) : + table->file->rnd_init(1) || + table->file->rnd_next(table->record[0]); + mode=RNEXT; + break; case RLAST: - err=table->file->index_last(table->record[0]); - mode=RPREV; - break; + dbug_assert(keyname != 0); + err=table->file->index_last(table->record[0]); + mode=RPREV; + break; case RNEXT: - err=table->file->index_next(table->record[0]); - break; + err=keyname ? + table->file->index_next(table->record[0]) : + table->file->rnd_next(table->record[0]); + break; case RPREV: - err=table->file->index_prev(table->record[0]); - break; + dbug_assert(keyname != 0); + err=table->file->index_prev(table->record[0]); + break; case RKEY: - { - KEY *keyinfo=table->key_info+keyno; - uint key_len=0, i; - byte *key, *buf; - if (key_expr->elements > keyinfo->key_parts) - { - my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), - MYF(0),keyinfo->key_parts); - return -1; - } - for (i=0; i < key_expr->elements; i++) - key_len+=keyinfo->key_part[i].store_length; - if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) - { - send_error(&thd->net,ER_OUTOFMEMORY); - return -1; - } - List_iterator it_ke(*key_expr); - for (i=0, buf=key; i < key_expr->elements; i++) - { - uint maybe_null= test(keyinfo->key_part[i].null_bit); - store_key_item ski=store_key_item(keyinfo->key_part[i].field, - (char*)buf+maybe_null,maybe_null ? (char*) buf : 0, - keyinfo->key_part[i].length, it_ke++); - ski.copy(); - buf+=keyinfo->key_part[i].store_length; - } - err=table->file->index_read(table->record[0], - key,key_len,ha_rkey_mode); - mode=rkey_to_rnext[(int)ha_rkey_mode]; - break; - } + { + dbug_assert(keyname != 0); + KEY *keyinfo=table->key_info+keyno; + KEY_PART_INFO *key_part=keyinfo->key_part; + uint key_len; + byte *key; + if (key_expr->elements > keyinfo->key_parts) + { + my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), + MYF(0),keyinfo->key_parts); + goto err; + } + List_iterator it_ke(*key_expr); + Item *item; + for (key_len=0 ; (item=it_ke++) ; key_part++) + { + item->save_in_field(key_part->field); + key_len+=key_part->store_length; + } + if (!(key=sql_calloc(ALIGN_SIZE(key_len)))) + { + send_error(&thd->net,ER_OUTOFMEMORY); + goto err; + } + key_copy(key, table, keyno, key_len); + err=table->file->index_read(table->record[0], + key,key_len,ha_rkey_mode); + mode=rkey_to_rnext[(int)ha_rkey_mode]; + break; + } default: - send_error(&thd->net,ER_ILLEGAL_HA); - return -1; + send_error(&thd->net,ER_ILLEGAL_HA); + goto err; } - if (err && err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) + if (err) { - sql_print_error("mysql_ha_read: Got error %d when reading table", - err); - table->file->print_error(err,MYF(0)); - return -1; + if (err != HA_ERR_KEY_NOT_FOUND && err != HA_ERR_END_OF_FILE) + { + sql_print_error("mysql_ha_read: Got error %d when reading table", + err); + table->file->print_error(err,MYF(0)); + goto err; + } + goto ok; + } + if (cond) + { + err=err; + if(!cond->val_int()) + continue; } if (num_rows>=offset_limit) { - if (num_rows==offset_limit) send_fields(thd,list,1); if (!err) { - String *packet = &thd->packet; - Item *item; - packet->length(0); - it.rewind(); - while ((item=it++)) - { - if (item->send(packet)) - { - packet->free(); // Free used - my_error(ER_OUT_OF_RESOURCES,MYF(0)); - return -1; - } - } - my_net_write(&thd->net, (char*)packet->ptr(), packet->length()); + String *packet = &thd->packet; + Item *item; + packet->length(0); + it.rewind(); + while ((item=it++)) + { + if (item->send(packet)) + { + packet->free(); // Free used + my_error(ER_OUT_OF_RESOURCES,MYF(0)); + goto err; + } + } + my_net_write(&thd->net, (char*)packet->ptr(), packet->length()); } } + num_rows++; } +ok: + mysql_unlock_tables(thd,lock); send_eof(&thd->net); return 0; +err: + mysql_unlock_tables(thd,lock); + return -1; } /************************************************************************** @@ -184,10 +239,10 @@ static TABLE *find_table_by_name(THD *thd, char *db, char *table_name) if (!db || ! *db) db=""; dblen=strlen(db); - for (TABLE *table=thd->open_tables; table ; table=table->next) + for (TABLE *table=thd->handler_tables; table ; table=table->next) { if (!memcmp(table->table_cache_key, db, dblen) && - !my_strcasecmp(table->table_name,table_name)) + !my_strcasecmp(table->table_name,table_name)) return table; } return(0); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 72f163ec677..ea0531fb765 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2009,8 +2009,8 @@ mysql_execute_command(void) case SQLCOM_HA_READ: if (check_db_used(thd,tables) || check_table_access(thd,SELECT_ACL, tables)) goto error; - res = mysql_ha_read(thd, tables, lex->ha_read_mode, - lex->backup_dir, lex->insert_list, lex->ha_rkey_mode, + res = mysql_ha_read(thd, tables, lex->ha_read_mode, lex->backup_dir, + lex->insert_list, lex->ha_rkey_mode, lex->where, lex->select_limit, lex->offset_limit); break; @@ -2059,7 +2059,7 @@ mysql_execute_command(void) } thd->proc_info="query end"; // QQ if (res < 0) - send_error(&thd->net,thd->killed ? ER_SERVER_SHUTDOWN : 0, 0); + send_error(&thd->net,thd->killed ? ER_SERVER_SHUTDOWN : 0); error: DBUG_VOID_RETURN; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9942be1506f..214227ba063 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -535,7 +535,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); equal optional_braces opt_key_definition key_usage_list2 opt_mi_check_type opt_to mi_check_types normal_join table_to_table_list table_to_table opt_table_list opt_as - handler_read_function handler_rkey_mode END_OF_INPUT + handler_rkey_function handler_rkey_mode handler_read_or_scan + END_OF_INPUT %type '-' '+' '*' '/' '%' '(' ')' @@ -1904,7 +1905,8 @@ order_dir: limit_clause: /* empty */ { - Lex->select_limit= current_thd->default_select_limit; + Lex->select_limit= (Lex->sql_command == SQLCOM_HA_READ) ? + 1 : current_thd->default_select_limit; Lex->offset_limit= 0L; } | LIMIT ULONG_NUM @@ -2844,7 +2846,7 @@ unlock: /* -** Table: direct access to ISAM functions +** Handler: direct access to ISAM functions */ handler: @@ -2860,45 +2862,40 @@ handler: if (!add_table_to_list($2,0,0)) YYABORT; } - | HANDLER_SYM table_ident READ_SYM ident handler_read_function limit_clause + | HANDLER_SYM table_ident READ_SYM handler_read_or_scan { Lex->sql_command = SQLCOM_HA_READ; - Lex->backup_dir= $4.str; if (!add_table_to_list($2,0,0)) YYABORT; - } + } + where_clause limit_clause { } -handler_read_function: - FIRST_SYM - { - Lex->ha_read_mode = RFIRST; - } - | NEXT_SYM - { - Lex->ha_read_mode = RNEXT; - } - | PREV_SYM - { - Lex->ha_read_mode = RPREV; - } - | LAST_SYM - { - Lex->ha_read_mode = RLAST; - } +handler_read_or_scan: + handler_scan_function { Lex->backup_dir= 0; } + | ident handler_rkey_function { Lex->backup_dir= $1.str; } + +handler_scan_function: + FIRST_SYM { Lex->ha_read_mode = RFIRST; } + | NEXT_SYM { Lex->ha_read_mode = RNEXT; } + +handler_rkey_function: + FIRST_SYM { Lex->ha_read_mode = RFIRST; } + | NEXT_SYM { Lex->ha_read_mode = RNEXT; } + | PREV_SYM { Lex->ha_read_mode = RPREV; } + | LAST_SYM { Lex->ha_read_mode = RLAST; } | handler_rkey_mode { Lex->ha_read_mode = RKEY; if (!(Lex->insert_list = new List_item)) YYABORT; - } - '(' values ')' { } + } '(' values ')' { } handler_rkey_mode: - EQ { Lex->ha_rkey_mode=HA_READ_KEY_EXACT; } - | GE { Lex->ha_rkey_mode=HA_READ_KEY_OR_NEXT; } - | LE { Lex->ha_rkey_mode=HA_READ_KEY_OR_PREV; } - | GT_SYM {Lex->ha_rkey_mode=HA_READ_AFTER_KEY; } - | LT { Lex->ha_rkey_mode=HA_READ_BEFORE_KEY; } + EQ { Lex->ha_rkey_mode=HA_READ_KEY_EXACT; } + | GE { Lex->ha_rkey_mode=HA_READ_KEY_OR_NEXT; } + | LE { Lex->ha_rkey_mode=HA_READ_KEY_OR_PREV; } + | GT_SYM { Lex->ha_rkey_mode=HA_READ_AFTER_KEY; } + | LT { Lex->ha_rkey_mode=HA_READ_BEFORE_KEY; } /* GRANT / REVOKE */ -- cgit v1.2.1