1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Enhancing both multi-table delete and division of LEX

sql/filesort.cc:
  removing of some extra comments
sql/sql_class.h:
  Clear division between new and old stripping code
sql/sql_delete.cc:
  Stripping of unnecessary code and making it more efficient
sql/sql_parse.cc:
  Better split of LEX into two and enhancements in multi table delete
sql/sql_yacc.yy:
  More efficient division of LEX and optional syntax in multi - table delete
sql/uniques.cc:
  fixing some additional bugs
This commit is contained in:
unknown
2001-06-07 14:10:58 +03:00
parent 4e886689b2
commit 823586b2c7
6 changed files with 206 additions and 211 deletions

View File

@ -1059,7 +1059,7 @@ mysql_execute_command(void)
THD *thd=current_thd;
LEX *lex= &thd->lex;
TABLE_LIST *tables=(TABLE_LIST*) lex->select->table_list.first;
SELECT_LEX *Select = lex->select;
SELECT_LEX *select_lex = lex->select;
DBUG_ENTER("mysql_execute_command");
if(table_rules_on && thd->slave_thread && tables && !tables_ok(thd,tables))
@ -1071,7 +1071,7 @@ mysql_execute_command(void)
case SQLCOM_SELECT:
{
select_result *result;
if (Select->options & SELECT_DESCRIBE)
if (select_lex->options & SELECT_DESCRIBE)
lex->exchange=0;
if (tables)
{
@ -1089,12 +1089,12 @@ mysql_execute_command(void)
break; // Error message is given
}
thd->offset_limit=Select->offset_limit;
thd->select_limit=Select->select_limit+Select->offset_limit;
if (thd->select_limit < Select->select_limit)
thd->offset_limit=select_lex->offset_limit;
thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
if (thd->select_limit < select_lex->select_limit)
thd->select_limit= HA_POS_ERROR; // no limit
if (thd->select_limit == HA_POS_ERROR)
Select->options&= ~OPTION_FOUND_ROWS;
select_lex->options&= ~OPTION_FOUND_ROWS;
if (lex->exchange)
{
@ -1119,8 +1119,8 @@ mysql_execute_command(void)
{
res= -1;
#ifdef DELETE_ITEMS
delete Select->having;
delete Select->where;
delete select_lex->having;
delete select_lex->where;
#endif
break;
}
@ -1138,22 +1138,22 @@ mysql_execute_command(void)
if (!(res=open_and_lock_tables(thd,tables)))
{
res=mysql_select(thd,tables,Select->item_list,
Select->where,
Select->ftfunc_list,
(ORDER*) Select->order_list.first,
(ORDER*) Select->group_list.first,
Select->having,
res=mysql_select(thd,tables,select_lex->item_list,
select_lex->where,
select_lex->ftfunc_list,
(ORDER*) select_lex->order_list.first,
(ORDER*) select_lex->group_list.first,
select_lex->having,
(ORDER*) lex->proc_list.first,
Select->options | thd->options,
select_lex->options | thd->options,
result);
if (res)
result->abort();
}
delete result;
#ifdef DELETE_ITEMS
delete Select->having;
delete Select->where;
delete select_lex->having;
delete select_lex->where;
#endif
break;
}
@ -1272,7 +1272,7 @@ mysql_execute_command(void)
res=0;
break;
}
if (Select->item_list.elements) // With select
if (select_lex->item_list.elements) // With select
{
select_result *result;
@ -1290,9 +1290,9 @@ mysql_execute_command(void)
for (table = tables->next ; table ; table=table->next)
table->lock_type= lex->lock_option;
}
thd->offset_limit=Select->offset_limit;
thd->select_limit=Select->select_limit+Select->offset_limit;
if (thd->select_limit < Select->select_limit)
thd->offset_limit=select_lex->offset_limit;
thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
if (thd->select_limit < select_lex->select_limit)
thd->select_limit= HA_POS_ERROR; // No limit
if (!(res=open_and_lock_tables(thd,tables->next)))
@ -1301,16 +1301,16 @@ mysql_execute_command(void)
tables->real_name, &lex->create_info,
lex->create_list,
lex->key_list,
Select->item_list,lex->duplicates)))
select_lex->item_list,lex->duplicates)))
{
res=mysql_select(thd,tables->next,Select->item_list,
Select->where,
Select->ftfunc_list,
(ORDER*) Select->order_list.first,
(ORDER*) Select->group_list.first,
Select->having,
res=mysql_select(thd,tables->next,select_lex->item_list,
select_lex->where,
select_lex->ftfunc_list,
(ORDER*) select_lex->order_list.first,
(ORDER*) select_lex->group_list.first,
select_lex->having,
(ORDER*) lex->proc_list.first,
Select->options | thd->options,
select_lex->options | thd->options,
result);
if (res)
result->abort();
@ -1365,10 +1365,10 @@ mysql_execute_command(void)
}
if (!tables->db)
tables->db=thd->db;
if (!Select->db)
Select->db=tables->db;
if (!select_lex->db)
select_lex->db=tables->db;
if (check_access(thd,ALTER_ACL,tables->db,&tables->grant.privilege) ||
check_access(thd,INSERT_ACL | CREATE_ACL,Select->db,&priv) ||
check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv) ||
check_merge_table_access(thd, tables->db,
(TABLE_LIST *)
lex->create_info.merge_list.first))
@ -1384,7 +1384,7 @@ mysql_execute_command(void)
TABLE_LIST tmp_table;
bzero((char*) &tmp_table,sizeof(tmp_table));
tmp_table.real_name=lex->name;
tmp_table.db=Select->db;
tmp_table.db=select_lex->db;
tmp_table.grant.privilege=priv;
if (check_grant(thd,INSERT_ACL | CREATE_ACL,tables))
goto error;
@ -1394,11 +1394,11 @@ mysql_execute_command(void)
if (end_active_trans(thd))
res= -1;
else
res= mysql_alter_table(thd, Select->db, lex->name,
res= mysql_alter_table(thd, select_lex->db, lex->name,
&lex->create_info,
tables, lex->create_list,
lex->key_list, lex->drop_list, lex->alter_list,
(ORDER *) Select->order_list.first,
(ORDER *) select_lex->order_list.first,
lex->drop_primary, lex->duplicates,
lex->alter_keys_onoff, lex->simple_alter);
break;
@ -1518,22 +1518,22 @@ mysql_execute_command(void)
goto error;
if (grant_option && check_grant(thd,UPDATE_ACL,tables))
goto error;
if (Select->item_list.elements != lex->value_list.elements)
if (select_lex->item_list.elements != lex->value_list.elements)
{
send_error(&thd->net,ER_WRONG_VALUE_COUNT);
DBUG_VOID_RETURN;
}
res = mysql_update(thd,tables,
Select->item_list,
select_lex->item_list,
lex->value_list,
Select->where,
(ORDER *) Select->order_list.first,
Select->select_limit,
select_lex->where,
(ORDER *) select_lex->order_list.first,
select_lex->select_limit,
lex->duplicates,
lex->lock_option);
#ifdef DELETE_ITEMS
delete Select->where;
delete select_lex->where;
#endif
break;
case SQLCOM_INSERT:
@ -1577,9 +1577,9 @@ mysql_execute_command(void)
}
select_result *result;
thd->offset_limit=Select->offset_limit;
thd->select_limit=Select->select_limit+Select->offset_limit;
if (thd->select_limit < Select->select_limit)
thd->offset_limit=select_lex->offset_limit;
thd->select_limit=select_lex->select_limit+select_lex->offset_limit;
if (thd->select_limit < select_lex->select_limit)
thd->select_limit= HA_POS_ERROR; // No limit
if (check_dup(thd,tables->db,tables->real_name,tables->next))
@ -1599,14 +1599,14 @@ mysql_execute_command(void)
lex->sql_command == SQLCOM_REPLACE_SELECT ?
DUP_REPLACE : DUP_IGNORE)))
{
res=mysql_select(thd,tables->next,Select->item_list,
Select->where,
Select->ftfunc_list,
(ORDER*) Select->order_list.first,
(ORDER*) Select->group_list.first,
Select->having,
res=mysql_select(thd,tables->next,select_lex->item_list,
select_lex->where,
select_lex->ftfunc_list,
(ORDER*) select_lex->order_list.first,
(ORDER*) select_lex->group_list.first,
select_lex->having,
(ORDER*) lex->proc_list.first,
Select->options | thd->options,
select_lex->options | thd->options,
result);
delete result;
}
@ -1614,14 +1614,14 @@ mysql_execute_command(void)
res= -1;
}
#ifdef DELETE_ITEMS
delete Select->having;
delete Select->where;
delete select_lex->having;
delete select_lex->where;
#endif
break;
}
case SQLCOM_TRUNCATE:
Select->where=0;
Select->select_limit=HA_POS_ERROR;
select_lex->where=0;
select_lex->select_limit=HA_POS_ERROR;
/* Fall through */
case SQLCOM_DELETE:
{
@ -1635,8 +1635,8 @@ mysql_execute_command(void)
if (lex->sql_command == SQLCOM_TRUNCATE && end_active_trans(thd))
res= -1;
else
res = mysql_delete(thd,tables, Select->where, (ORDER*)Select->order_list.first,
Select->select_limit, lex->lock_option, Select->options);
res = mysql_delete(thd,tables, select_lex->where, (ORDER*)select_lex->order_list.first,
select_lex->select_limit, lex->lock_option, select_lex->options);
break;
}
case SQLCOM_MULTI_DELETE:
@ -1645,17 +1645,15 @@ mysql_execute_command(void)
multi_delete *result;
if (!tables || !aux_tables ||
check_table_access(thd,SELECT_ACL, tables) ||
check_table_access(thd,DELETE_ACL,aux_tables))
check_table_access(thd,SELECT_ACL, tables) ||
check_table_access(thd,DELETE_ACL,aux_tables))
{
res=-1;
goto error;
}
if (!tables->db)
tables->db=thd->db;
if (!aux_tables->db)
aux_tables->db=thd->db;
if ((thd->options & OPTION_SAFE_UPDATES) && !Select->where)
if ((thd->options & OPTION_SAFE_UPDATES) && !select_lex->where)
{
send_error(&thd->net,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE);
res=1; goto error;
@ -1664,66 +1662,42 @@ mysql_execute_command(void)
for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next, howmuch++)
{
if (!auxi->db)
auxi->db=thd->db;
auxi->db=thd->db;
if (!auxi->real_name)
auxi->real_name=auxi->name;
auxi->real_name=auxi->name;
for (walk=(TABLE_LIST*) tables ; walk ; walk=walk->next)
{
if (!walk->db) walk->db=thd->db;
if (!strcmp(auxi->real_name,walk->real_name) && !strcmp(walk->db,auxi->db))
break;
if (!walk->db) walk->db=thd->db;
if (!strcmp(auxi->real_name,walk->real_name) && !strcmp(walk->db,auxi->db))
break;
}
if (!walk)
{
net_printf(&thd->net,ER_NONUNIQ_TABLE,auxi->real_name);
res=-2; goto error;
net_printf(&thd->net,ER_NONUNIQ_TABLE,auxi->real_name);
res=-2; goto error;
}
else
auxi->lock_type=walk->lock_type=TL_WRITE;
TABLE form; char path[FN_REFLEN];
(void)sprintf(path,"%s/%s/%s",mysql_data_home,auxi->db,auxi->name);
if (openfrm(path,auxi->name,(uint)HA_TRY_READ_ONLY,COMPUTE_TYPES,0,&form))
{
res=-1; goto error;
auxi->lock_type=walk->lock_type=TL_WRITE;
auxi->table= (TABLE *) walk;
}
char *field_name=sql_strdup(form.fieldnames.type_names[0]); VOID(closefrm(&form));
if (add_item_to_list(new Item_field(auxi->db,auxi->name,field_name)))
{
net_printf(&thd->net,ER_WRONG_TABLE_NAME,auxi->name);
res=-1; goto error;
}
}
if (!howmuch--)
{
my_error(ER_NO_TABLES_USED, MYF(0));
res=-2; goto error;
}
tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege);
if (add_item_to_list(new Item_null())) goto error;
thd->proc_info="init";
if (open_and_lock_tables(thd,tables))
{
res=-1; goto error;
}
/* This double loop definitely looks like it could have been merged up. But not !!
* Problmes are that we have to first set lock for tables to be deleted to write
* and then to get auxi->table from tables, like below .....
*/
for (auxi=(TABLE_LIST*) aux_tables ; auxi ; auxi=auxi->next)
{
for (walk=(TABLE_LIST*) tables ; walk ; walk=walk->next)
{
if (!strcmp(auxi->real_name,walk->real_name) && !strcmp(walk->db,auxi->db))
break;
}
auxi->table = walk->table;
}
auxi->table= ((TABLE_LIST*) auxi->table)->table;
if ((result=new multi_delete(aux_tables,lex->lock_option,howmuch)))
{
res=mysql_select(thd,tables,Select->item_list,
Select->where,Select->ftfunc_list,
res=mysql_select(thd,tables,select_lex->item_list,
select_lex->where,select_lex->ftfunc_list,
(ORDER *)NULL,(ORDER *)NULL,(Item *)NULL,
(ORDER *)NULL,
Select->options | thd->options,
select_lex->options | thd->options,
result);
delete result;
}
@ -1797,7 +1771,7 @@ mysql_execute_command(void)
DBUG_VOID_RETURN;
#else
{
char *db=Select->db ? Select->db : thd->db;
char *db=select_lex->db ? select_lex->db : thd->db;
if (!db)
{
send_error(&thd->net,ER_NO_DB_ERROR); /* purecov: inspected */
@ -1812,7 +1786,7 @@ mysql_execute_command(void)
if (check_access(thd,SELECT_ACL,db,&thd->col_access))
goto error; /* purecov: inspected */
/* grant is checked in mysqld_show_tables */
if (Select->options & SELECT_DESCRIBE)
if (select_lex->options & SELECT_DESCRIBE)
res= mysqld_extend_show_tables(thd,db,
(lex->wild ? lex->wild->ptr() : NullS));
else
@ -1877,7 +1851,7 @@ mysql_execute_command(void)
}
#endif
case SQLCOM_CHANGE_DB:
mysql_change_db(thd,Select->db);
mysql_change_db(thd,select_lex->db);
break;
case SQLCOM_LOAD:
{
@ -1901,10 +1875,10 @@ mysql_execute_command(void)
case SQLCOM_SET_OPTION:
{
uint org_options=thd->options;
thd->options=Select->options;
thd->options=select_lex->options;
thd->update_lock_default= ((thd->options & OPTION_LOW_PRIORITY_UPDATES) ?
TL_WRITE_LOW_PRIORITY : TL_WRITE);
thd->default_select_limit=Select->select_limit;
thd->default_select_limit=select_lex->select_limit;
thd->tx_isolation=lex->tx_isolation;
if (thd->gemini_spin_retries != lex->gemini_spin_retries)
{
@ -1915,7 +1889,7 @@ mysql_execute_command(void)
thd->options,(long) thd->default_select_limit));
/* Check if auto_commit mode changed */
if ((org_options ^ Select->options) & OPTION_NOT_AUTO_COMMIT)
if ((org_options ^ select_lex->options) & OPTION_NOT_AUTO_COMMIT)
{
if ((org_options & OPTION_NOT_AUTO_COMMIT))
{
@ -2025,7 +1999,7 @@ mysql_execute_command(void)
if (tables && !tables->db)
tables->db=thd->db;
if (check_access(thd, lex->grant | lex->grant_tot_col | GRANT_ACL,
tables && tables->db ? tables->db : Select->db,
tables && tables->db ? tables->db : select_lex->db,
tables ? &tables->grant.privilege : 0,
tables ? 0 : 1))
goto error;
@ -2077,7 +2051,7 @@ mysql_execute_command(void)
res=1;
}
else
res = mysql_grant(thd, Select->db, lex->users_list, lex->grant,
res = mysql_grant(thd, select_lex->db, lex->users_list, lex->grant,
lex->sql_command == SQLCOM_REVOKE);
if(!res)
{
@ -2125,8 +2099,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, Select->where,
Select->select_limit, Select->offset_limit);
lex->insert_list, lex->ha_rkey_mode, select_lex->where,
select_lex->select_limit, select_lex->offset_limit);
break;
case SQLCOM_BEGIN:
@ -2403,19 +2377,19 @@ mysql_init_query(THD *thd)
void
mysql_init_select(LEX *lex)
{
SELECT_LEX *Select = lex->select;
Select->where=Select->having=0;
Select->select_limit=current_thd->default_select_limit;
Select->offset_limit=0L;
Select->options=0; Select->linkage=UNSPECIFIED_TYPE;
Select->select_number = 0; lex->exchange = 0;
SELECT_LEX *select_lex = lex->select;
select_lex->where=select_lex->having=0;
select_lex->select_limit=current_thd->default_select_limit;
select_lex->offset_limit=0L;
select_lex->options=0; select_lex->linkage=UNSPECIFIED_TYPE;
select_lex->select_number = 0; lex->exchange = 0;
lex->proc_list.first=0;
Select->order_list.elements=Select->group_list.elements=0;
Select->order_list.first=0;
Select->order_list.next= (byte**) &Select->order_list.first;
Select->group_list.first=0;
Select->group_list.next= (byte**) &Select->group_list.first;
Select->next = (SELECT_LEX *)NULL;
select_lex->order_list.elements=select_lex->group_list.elements=0;
select_lex->order_list.first=0;
select_lex->order_list.next= (byte**) &select_lex->order_list.first;
select_lex->group_list.first=0;
select_lex->group_list.next= (byte**) &select_lex->group_list.first;
select_lex->next = (SELECT_LEX *)NULL;
}