From 2dae97b139287c0b607ef01087c91090c16f5a04 Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Thu, 3 Oct 2002 13:12:31 +0500 Subject: [PATCH 1/3] Failed to compile on FreeBSD: no ulong type, one should use unsigned long instead --- include/mysql.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 376de1a0e08..64b118ca8b1 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -447,7 +447,7 @@ typedef struct st_mysql_stmt unsigned long param_count; /* parameters count */ unsigned long field_count; /* fields count */ unsigned long long_length; /* long buffer alloced length */ - ulong stmt_id; /* Id for prepared statement */ + unsigned long stmt_id; /* Id for prepared statement */ uint last_errno; /* error code */ enum MY_STMT_STATE state; /* statement state */ char last_error[MYSQL_ERRMSG_SIZE]; /* error message */ @@ -506,7 +506,7 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); my_bool simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, - ulong length, my_bool skip_check); + unsigned long length, my_bool skip_check); unsigned long net_safe_read(MYSQL* mysql); #ifdef __cplusplus From 032a4a927a8c8a3b8d7d585abbfc2db930f08ed4 Mon Sep 17 00:00:00 2001 From: "ram@mysql.r18.ru" <> Date: Thu, 3 Oct 2002 14:55:02 +0500 Subject: [PATCH 2/3] Additional key segment (HA_KEYTYPE_END) creation has been moved from handler to hp_create.c --- BitKeeper/etc/logging_ok | 1 + heap/hp_create.c | 18 +++++++++++------- sql/ha_heap.cc | 13 ------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 31c8d0a3253..866b5cfd3c3 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -74,3 +74,4 @@ WAX@sergbook.mysql.com bar@bar.udmsearch.izhnet.ru nick@mysql.com bar@bar.mysql.r18.ru +ram@mysql.r18.ru diff --git a/heap/hp_create.c b/heap/hp_create.c index 4163f5b0217..7eee6eaa64d 100644 --- a/heap/hp_create.c +++ b/heap/hp_create.c @@ -85,15 +85,24 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, memcpy(share->keydef, keydef, (size_t) (sizeof(keydef[0]) * keys)); for (i= 0, keyinfo= share->keydef; i < keys; i++, keyinfo++) { - uint nsegs= keydef[i].keysegs; + keyinfo->seg= keyseg; + memcpy(keyseg, keydef[i].seg, + (size_t) (sizeof(keyseg[0]) * keydef[i].keysegs)); + keyseg+= keydef[i].keysegs; if (keydef[i].algorithm == HA_KEY_ALG_BTREE) { + /* additional HA_KEYTYPE_END keyseg */ + keyseg->type= HA_KEYTYPE_END; + keyseg->length= sizeof(byte*); + keyseg->flag= 0; + keyseg->null_bit= 0; + keyseg++; + init_tree(&keyinfo->rb_tree, 0, 0, sizeof(byte*), (qsort_cmp2)keys_compare, 1, NULL, NULL); keyinfo->delete_key= hp_rb_delete_key; keyinfo->write_key= hp_rb_write_key; - nsegs++; } else { @@ -102,12 +111,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, keyinfo->delete_key= hp_delete_key; keyinfo->write_key= hp_write_key; } - keyinfo->seg= keyseg; - memcpy(keyseg, keydef[i].seg, - (size_t) (sizeof(keyseg[0]) * nsegs)); - keyseg+= nsegs; } - share->min_records= min_records; share->max_records= max_records; share->data_length= share->index_length= 0; diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index f56bfe74265..b41ab648f0b 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -243,11 +243,7 @@ int ha_heap::create(const char *name, TABLE *table, HA_CREATE_INFO *create_info) int error; for (key= parts= 0; key < table->keys; key++) - { parts+= table->key_info[key].key_parts; - if (table->key_info[key].algorithm == HA_KEY_ALG_BTREE) - parts++; /* additional HA_KEYTYPE_END keyseg */ - } if (!(keydef= (HP_KEYDEF*) my_malloc(table->keys * sizeof(HP_KEYDEF) + parts * sizeof(HA_KEYSEG), MYF(MY_WME)))) @@ -299,15 +295,6 @@ int ha_heap::create(const char *name, TABLE *table, HA_CREATE_INFO *create_info) seg->null_pos= 0; } } - if (pos->algorithm == HA_KEY_ALG_BTREE) - { - /* additional HA_KEYTYPE_END keyseg */ - seg->type= HA_KEYTYPE_END; - seg->length= sizeof(byte*); - seg->flag= 0; - seg->null_bit= 0; - seg++; - } } mem_per_row+= MY_ALIGN(table->reclength + 1, sizeof(char*)); max_rows= (ulong) (max_heap_table_size / mem_per_row); From 48b2a76a48e0655285326b24889c0ece4bee9da7 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 3 Oct 2002 16:35:08 +0300 Subject: [PATCH 3/3] after merging bugfix --- sql/item.cc | 21 +++++++++++++++------ sql/mysql_priv.h | 5 +++-- sql/sql_base.cc | 23 +++++++++++++---------- sql/sql_lex.cc | 10 +++++----- sql/sql_parse.cc | 2 +- sql/sql_select.cc | 11 ++++------- sql/sql_yacc.yy | 9 ++++++--- 7 files changed, 47 insertions(+), 34 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 946c0f24fe1..47c2926bef4 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -432,7 +432,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!field) // If field is not checked { Field *tmp; - if (!(tmp=find_field_in_tables(thd,this,tables))) + if (!(tmp=find_field_in_tables(thd, this, tables, 0))) { /* We can't find table field in table list of current select, @@ -448,9 +448,14 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) sl && !tmp; sl= sl->outer_select()) tmp=find_field_in_tables(thd, this, - (TABLE_LIST*)(last= sl)->table_list.first); + (TABLE_LIST*)(last= sl)->table_list.first, + 0); if (!tmp) - return 1; + { + // Call to produce appropriate error message + find_field_in_tables(thd, this, tables, 1); + return -1; + } else { depended_from= last; @@ -463,7 +468,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) s= s->outer_select()) if( !s->depended ) { - s->depended= 1; //Select is depended of outer select + s->depended= 1; //Tables will be reopened many times for (TABLE_LIST *tbl= (TABLE_LIST*)s->table_list.first; @@ -780,7 +785,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) { if (!ref) { - if (!(ref= find_item_in_list(this,thd->lex.select->item_list))) + if (!(ref= find_item_in_list(this, thd->lex.select->item_list, 0))) { /* We can't find table field in table list of current select, @@ -795,9 +800,13 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) for (SELECT_LEX *sl= thd->lex.select->outer_select(); sl && !ref; sl= sl->outer_select()) - ref= find_item_in_list(this, (last= sl)->item_list); + ref= find_item_in_list(this, (last= sl)->item_list, 0); if (!ref) + { + // Call to report error + find_item_in_list(this, thd->lex.select->item_list, 1); return 1; + } else { depended_from= last; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 4532646b1c2..60505ec0712 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -450,7 +450,8 @@ bool wait_for_tables(THD *thd); bool table_is_used(TABLE *table, bool wait_for_name_lock); bool drop_locked_tables(THD *thd,const char *db, const char *table_name); void abort_locked_tables(THD *thd,const char *db, const char *table_name); -Field *find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables); +Field *find_field_in_tables(THD *thd, Item_field *item, TABLE_LIST *tables, + bool report_error); Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, bool check_grant,bool allow_rowid); #ifdef HAVE_OPENSSL @@ -538,7 +539,7 @@ 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); +Item ** find_item_in_list(Item *item, List &items, bool report_error); bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, const char *table_name, List_iterator *it); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 5d3421f5538..59c57006947 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1783,7 +1783,8 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, Field * -find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) +find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables, + bool report_error) { Field *found=0; const char *db=item->db_name; @@ -1820,7 +1821,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) } if (found) return found; - if (!found_table) + if (!found_table && report_error) { char buff[NAME_LEN*2+1]; if (db) @@ -1832,8 +1833,9 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) thd->where); } else - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), - item->full_name(),thd->where); + if (report_error) + my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), + item->full_name(),thd->where); return (Field*) 0; } bool allow_rowid= tables && !tables->next; // Only one table @@ -1848,7 +1850,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) return (Field*) 0; if (found) { - if (!thd->where) // Returns first found + if (!report_error) // Returns first found break; my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), name,thd->where); @@ -1859,13 +1861,14 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) } if (found) return found; - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR), - MYF(0),item->full_name(),thd->where); + if (report_error) + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), + MYF(0), item->full_name(), thd->where); return (Field*) 0; } Item ** -find_item_in_list(Item *find,List &items) +find_item_in_list(Item *find, List &items, bool report_error) { List_iterator li(items); Item **found=0,*item; @@ -1890,7 +1893,7 @@ find_item_in_list(Item *find,List &items) { if ((*found)->eq(item,0)) continue; // Same field twice (Access?) - if (current_thd->where) + if (report_error) my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), find->full_name(), current_thd->where); return (Item**) 0; @@ -1913,7 +1916,7 @@ find_item_in_list(Item *find,List &items) break; } } - if (!found && current_thd->where) + if (!found && report_error) my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), find->full_name(),current_thd->where); return found; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 1af8d363fda..60ab3344b3f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -142,11 +142,11 @@ LEX *lex_start(THD *thd, uchar *buf,uint length) lex->next_state=STATE_START; lex->end_of_query=(lex->ptr=buf)+length; lex->yylineno = 1; - lex->select->create_refs=lex->in_comment=0; + lex->select_lex.create_refs=lex->in_comment=0; lex->length=0; - lex->select->in_sum_expr=0; - lex->select->expr_list.empty(); - lex->select->ftfunc_list.empty(); + lex->select_lex.in_sum_expr=0; + lex->select_lex.expr_list.empty(); + lex->select_lex.ftfunc_list.empty(); lex->convert_set=(lex->thd=thd)->variables.convert_set; lex->yacc_yyss=lex->yacc_yyvs=0; lex->ignore_space=test(thd->sql_mode & MODE_IGNORE_SPACE); @@ -158,7 +158,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length) void lex_end(LEX *lex) { - lex->select->expr_list.delete_elements(); // If error when parsing sql-varargs + lex->select_lex.expr_list.delete_elements(); // If error when parsing sql-varargs x_free(lex->yacc_yyss); x_free(lex->yacc_yyvs); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 461276900a5..580a6796911 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1265,7 +1265,7 @@ mysql_execute_command(THD *thd) int res= 0; LEX *lex= &thd->lex; TABLE_LIST *tables= (TABLE_LIST*) lex->select_lex.table_list.first; - SELECT_LEX *select_lex= lex->select; + SELECT_LEX *select_lex= &lex->select_lex; SELECT_LEX_UNIT *unit= &lex->unit; DBUG_ENTER("mysql_execute_command"); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2b737ab65d7..68871d7ace1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6498,9 +6498,7 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List &fields, return 0; } const char *save_where=thd->where; - thd->where=0; // No error if not found - Item **item=find_item_in_list(*order->item,fields); - thd->where=save_where; + Item **item=find_item_in_list(*order->item, fields, 0); if (item) { order->item=item; // use it @@ -6598,17 +6596,15 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List &fields, DBUG_ENTER("setup_new_fields"); thd->set_query_id=1; // Not really needed, but... - thd->where=0; // Don't give error for (; new_field ; new_field=new_field->next) { - if ((item=find_item_in_list(*new_field->item,fields))) + if ((item= find_item_in_list(*new_field->item, fields, 0))) new_field->item=item; /* Change to shared Item */ else { thd->where="procedure list"; if ((*new_field->item)->fix_fields(thd, tables, new_field->item)) DBUG_RETURN(1); /* purecov: inspected */ - thd->where=0; all_fields.push_front(*new_field->item); new_field->item=all_fields.head_ref(); } @@ -7400,7 +7396,8 @@ static void describe_info(JOIN *join, const char *info) { THD *thd= join->thd; - if (thd->lex.select->next_select()) /* If in UNION */ + /* If lex.select belong to UNION */ + if (thd->lex.select->master_unit()->first_select()->next_select()) { select_describe(join,FALSE,FALSE,FALSE,info); return; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cc06344304f..f61f970f479 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2436,7 +2436,8 @@ order_clause: net_printf(lex->thd, ER_WRONG_USAGE, "UPDATE", "ORDER BY"); YYABORT; } - if (lex->select->olap != UNSPECIFIED_OLAP_TYPE) + if (lex->select->linkage != GLOBAL_OPTIONS_TYPE && + lex->select->olap != UNSPECIFIED_OLAP_TYPE) { net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP", @@ -2462,7 +2463,8 @@ limit_clause: | LIMIT ULONG_NUM { LEX *lex=Lex; - if (lex->select->olap != UNSPECIFIED_OLAP_TYPE) + if (lex->select->linkage != GLOBAL_OPTIONS_TYPE && + lex->select->olap != UNSPECIFIED_OLAP_TYPE) { net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP", "LIMIT"); @@ -2475,7 +2477,8 @@ limit_clause: | LIMIT ULONG_NUM ',' ULONG_NUM { LEX *lex=Lex; - if (lex->select->olap != UNSPECIFIED_OLAP_TYPE) + if (lex->select->linkage != GLOBAL_OPTIONS_TYPE && + lex->select->olap != UNSPECIFIED_OLAP_TYPE) { net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP", "LIMIT");