diff options
author | unknown <jcole@tetra.spaceapes.com> | 2000-11-11 23:27:23 -0600 |
---|---|---|
committer | unknown <jcole@tetra.spaceapes.com> | 2000-11-11 23:27:23 -0600 |
commit | 09b4480ed1b52a2aba0780c8de3d523badd9b761 (patch) | |
tree | 9d4ddae9f8a105ea62f9c8286bb4dce860339b59 /sql | |
parent | 6147228097979d230294d8607f462f2f0c56c397 (diff) | |
parent | 23f2aaf76bcb39e919d66dc48f0a25d1b7b6eab5 (diff) | |
download | mariadb-git-09b4480ed1b52a2aba0780c8de3d523badd9b761.tar.gz |
Merge jcole@work.mysql.com:/home/bk/mysql
into tetra.spaceapes.com:/usr/home/jcole/bk/mysql
BitKeeper/etc/logging_ok:
Auto merged
Docs/manual.texi:
Auto merged
sql/mysql_priv.h:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ChangeLog | 4 | ||||
-rw-r--r-- | sql/mysql_priv.h | 5 | ||||
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/sql_parse.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 9 | ||||
-rw-r--r-- | sql/sql_table.cc | 38 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 12 |
7 files changed, 56 insertions, 18 deletions
diff --git a/sql/ChangeLog b/sql/ChangeLog index 08bbd3bb0db..2289765afad 100644 --- a/sql/ChangeLog +++ b/sql/ChangeLog @@ -1,3 +1,7 @@ +2000-11-11 Jeremy Cole <jeremy@mysql.com> + +* Added ALTER TABLE ... ORDER BY ... + 2000-09-17 Michael Widenius <monty@mysql.com> * Added option QUICK to DELETE to tell MySQL not to balance the diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 384d98de40a..bc76b128d54 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -268,6 +268,10 @@ bool net_store_data(String *packet,const char *from,uint length); bool net_store_data(String *packet,struct tm *tmp); bool net_store_data(String* packet, I_List<i_string>* str_list); +SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length); +int setup_order(THD *thd,TABLE_LIST *tables, List<Item> &fields, + List <Item> &all_fields, ORDER *order); + int mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &list,COND *conds, List<Item_func_match> &ftfuncs, ORDER *order, ORDER *group,Item *having,ORDER *proc_param, @@ -294,6 +298,7 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name, List<create_field> &fields, List<Key> &keys,List<Alter_drop> &drop_list, List<Alter_column> &alter_list, + ORDER *order, bool drop_primary, enum enum_duplicates handle_duplicates); bool mysql_rename_table(enum db_type base, diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 584bacc237c..1c006a83ce7 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1905,7 +1905,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys) create_info.db_type=DB_TYPE_DEFAULT; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, - fields, keys, drop, alter, FALSE, DUP_ERROR)); + fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR)); } @@ -1920,7 +1920,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop) create_info.db_type=DB_TYPE_DEFAULT; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, - fields, keys, drop, alter, FALSE, DUP_ERROR)); + fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR)); } /***************************************************************************** diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 905b8a2af5e..066885ef30a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1158,6 +1158,7 @@ mysql_execute_command(void) &lex->create_info, tables, lex->create_list, lex->key_list, lex->drop_list, lex->alter_list, + (ORDER *) lex->order_list.first, lex->drop_primary, lex->duplicates); break; } @@ -1262,6 +1263,7 @@ mysql_execute_command(void) res= mysql_alter_table(thd, NullS, NullS, &create_info, tables, lex->create_list, lex->key_list, lex->drop_list, lex->alter_list, + (ORDER *) 0, 0,DUP_ERROR); } else diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 189b01c9782..c9de4998899 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -112,15 +112,12 @@ static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field, static int remove_dup_with_hash_index(THD *thd, TABLE *table, uint field_count, Field **first_field, ulong key_length); -static SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length); static int join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count); static ulong used_blob_length(CACHE_FIELD **ptr); static bool store_record_in_cache(JOIN_CACHE *cache); static void reset_cache(JOIN_CACHE *cache); static void read_cached_record(JOIN_TAB *tab); static bool cmp_buffer_with_ref(JOIN_TAB *tab); -static int setup_order(THD *thd,TABLE_LIST *tables, List<Item> &fields, - List <Item> &all_fields, ORDER *order); static int setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields, List<Item> &all_fields, ORDER *order, bool *hidden); static bool setup_new_fields(THD *thd,TABLE_LIST *tables,List<Item> &fields, @@ -5409,8 +5406,7 @@ err: } -static SORT_FIELD * -make_unireg_sortorder(ORDER *order, uint *length) +SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length) { uint count; SORT_FIELD *sort,*pos; @@ -5752,8 +5748,7 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List<Item> &fields, ** and doesn't exits in the select list, add it the the field list. */ -static int -setup_order(THD *thd,TABLE_LIST *tables,List<Item> &fields, +int setup_order(THD *thd,TABLE_LIST *tables,List<Item> &fields, List<Item> &all_fields, ORDER *order) { thd->where="order clause"; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 224e92ebe86..bcc0e4257f2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -32,6 +32,7 @@ static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end); static int copy_data_between_tables(TABLE *from,TABLE *to, List<create_field> &create, enum enum_duplicates handle_duplicates, + ORDER *order, ha_rows *copied,ha_rows *deleted); /***************************************************************************** @@ -1049,6 +1050,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, List<create_field> &fields, List<Key> &keys,List<Alter_drop> &drop_list, List<Alter_column> &alter_list, + ORDER *order, bool drop_primary, enum enum_duplicates handle_duplicates) { @@ -1416,7 +1418,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, thd->proc_info="copy to tmp table"; next_insert_id=thd->next_insert_id; // Remember for loggin error=copy_data_between_tables(table,new_table,create_list,handle_duplicates, - &copied,&deleted); + order, &copied,&deleted); thd->last_insert_id=next_insert_id; // Needed for correct log thd->count_cuted_fields=0; /* Don`t calc cuted fields */ new_table->time_stamp=save_time_stamp; @@ -1569,14 +1571,24 @@ end_temporary: static int -copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create, +copy_data_between_tables(TABLE *from,TABLE *to, + List<create_field> &create, enum enum_duplicates handle_duplicates, - ha_rows *copied,ha_rows *deleted) + ORDER *order, + ha_rows *copied, + ha_rows *deleted) { int error; Copy_field *copy,*copy_end; ulong found_count,delete_count; THD *thd= current_thd; + uint length; + SORT_FIELD *sortorder; + READ_RECORD info; + Field *next_field; + TABLE_LIST tables; + List<Item> fields; + List<Item> all_fields; DBUG_ENTER("copy_data_between_tables"); if (!(copy= new Copy_field[to->fields])) @@ -1597,11 +1609,25 @@ copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create, (copy_end++)->set(*ptr,def->field,0); } - READ_RECORD info; + if(order) { + from->io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE), + MYF(MY_FAE | MY_ZEROFILL)); + bzero((char*) &tables,sizeof(tables)); + tables.table = from; + error=1; + + if (setup_order(thd, &tables, fields, all_fields, order) || + !(sortorder=make_unireg_sortorder(order, &length)) || + (from->found_records = filesort(&from, sortorder, length, + (SQL_SELECT *) 0, 0L, HA_POS_ERROR)) + == HA_POS_ERROR) + goto err; + }; + init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1,1); found_count=delete_count=0; - Field *next_field=to->next_number_field; + next_field=to->next_number_field; while (!(error=info.read_record(&info))) { if (thd->killed) @@ -1640,6 +1666,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create, error=1; if (ha_commit(thd) || to->file->external_lock(thd,F_UNLCK)) error=1; + err: + free_io_cache(from); *copied= found_count; *deleted=delete_count; DBUG_RETURN(error > 0 ? -1 : 0); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f7497d605cc..5d62fbe84ba 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1030,14 +1030,18 @@ alter: lex->col_list.empty(); lex->drop_list.empty(); lex->alter_list.empty(); + lex->order_list.elements=0; + lex->order_list.first=0; + lex->order_list.next= (byte**) &lex->order_list.first; lex->db=lex->name=0; bzero((char*) &lex->create_info,sizeof(lex->create_info)); lex->create_info.db_type= DB_TYPE_DEFAULT; } - alter_list opt_create_table_options - + alter_list order_clause opt_create_table_options + alter_list: - alter_list_item + /* empty */ + | alter_list_item | alter_list ',' alter_list_item add_column: @@ -1075,7 +1079,7 @@ alter_list_item: { Lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0)); } | RENAME opt_to table_alias table_ident { Lex->db=$4->db.str ; Lex->name= $4->table.str; } - | create_table_option + | opt_create_table_options opt_column: /* empty */ {} |