summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authormonty@narttu.mysql.fi <>2003-05-03 16:22:56 +0300
committermonty@narttu.mysql.fi <>2003-05-03 16:22:56 +0300
commit5f028be2e6c8e7732c66294c87fff916924d5311 (patch)
tree85ae3a68c5b66cc20860d899e7e162aedbcd6210 /sql
parentb82f9ee8f7f08d88ee544364efc8d87de6831790 (diff)
parent7410b6cbdf21412f8cf4f6fc55713a2592f16f0e (diff)
downloadmariadb-git-5f028be2e6c8e7732c66294c87fff916924d5311.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-4.0
into narttu.mysql.fi:/my/mysql-4.0
Diffstat (limited to 'sql')
-rw-r--r--sql/opt_sum.cc14
-rw-r--r--sql/sql_base.cc5
-rw-r--r--sql/sql_update.cc25
3 files changed, 27 insertions, 17 deletions
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index aeaf8beef07..21296845c21 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -191,13 +191,13 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
ref.key_buff=key_buff;
TABLE *table=((Item_field*) expr)->field->table;
- if ((outer_tables & table->map) ||
- !find_range_key(&ref, ((Item_field*) expr)->field,conds))
+ if ((table->file->table_flags() & HA_NOT_READ_AFTER_KEY))
{
const_result=0;
break;
}
- if ((table->file->table_flags() & HA_NOT_READ_AFTER_KEY))
+ if ((outer_tables & table->map) ||
+ !find_range_key(&ref, ((Item_field*) expr)->field,conds))
{
const_result=0;
break;
@@ -348,7 +348,13 @@ bool part_of_cond(COND *cond,Field *field)
}
-/* Check if we can get value for field by using a key */
+/*
+ Check if we can get value for field by using a key
+
+ NOTES
+ This function may set table->key_read to 1, which must be reset after
+ index is used! (This can only happen when function returns 1)
+*/
static bool find_range_key(TABLE_REF *ref, Field* field, COND *cond)
{
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0f0c3c97ed2..f0aa8e9c351 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -482,8 +482,9 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
{
DBUG_ENTER("close_thread_table");
- bool found_old_table=0;
- TABLE *table=*table_ptr;
+ bool found_old_table= 0;
+ TABLE *table= *table_ptr;
+ DBUG_ASSERT(table->key_read == 0);
*table_ptr=table->next;
if (table->version != refresh_version ||
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 462206b25f3..0dc6073278f 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -62,6 +62,7 @@ int mysql_update(THD *thd,
int error=0;
uint used_index, want_privilege;
ulong query_id=thd->query_id, timestamp_query_id;
+ ha_rows updated, found;
key_map old_used_keys;
TABLE *table;
SQL_SELECT *select;
@@ -192,9 +193,8 @@ int mysql_update(THD *thd,
limit, &examined_rows)) ==
HA_POS_ERROR)
{
- delete select;
free_io_cache(table);
- DBUG_RETURN(-1);
+ goto err;
}
/*
Filesort has already found and selected the rows we want to update,
@@ -214,10 +214,7 @@ int mysql_update(THD *thd,
IO_CACHE tempfile;
if (open_cached_file(&tempfile, mysql_tmpdir,TEMP_PREFIX,
DISK_BUFFER_SIZE, MYF(MY_WME)))
- {
- delete select; /* purecov: inspected */
- DBUG_RETURN(-1);
- }
+ goto err;
init_read_record(&info,thd,table,select,0,1);
thd->proc_info="Searching rows for update";
@@ -256,10 +253,7 @@ int mysql_update(THD *thd,
error=1; /* purecov: inspected */
select->file=tempfile; // Read row ptrs from this file
if (error >= 0)
- {
- delete select;
- DBUG_RETURN(-1);
- }
+ goto err;
}
if (table->key_read)
{
@@ -272,7 +266,7 @@ int mysql_update(THD *thd,
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
init_read_record(&info,thd,table,select,0,1);
- ha_rows updated=0L,found=0L;
+ updated= found= 0;
thd->count_cuted_fields=1; /* calc cuted fields */
thd->cuted_fields=0L;
thd->proc_info="Updating";
@@ -365,6 +359,15 @@ int mysql_update(THD *thd,
thd->count_cuted_fields=0; /* calc cuted fields */
free_io_cache(table);
DBUG_RETURN(0);
+
+err:
+ delete select;
+ if (table->key_read)
+ {
+ table->key_read=0;
+ table->file->extra(HA_EXTRA_NO_KEYREAD);
+ }
+ DBUG_RETURN(-1);
}