summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <jani@ua141d10.elisa.omakaista.fi>2005-10-27 23:43:20 +0300
committerunknown <jani@ua141d10.elisa.omakaista.fi>2005-10-27 23:43:20 +0300
commit7911c50718fa27c2fa56e99d765b54267481a8d2 (patch)
treeff71298ae3c57caff8ca7c70666d60292290e366 /sql
parent6196a746116b4de60414f717eabcc243a7a3beb6 (diff)
parent987c33a97501ccd064ee2e68df44ad1d1e4618e6 (diff)
downloadmariadb-git-7911c50718fa27c2fa56e99d765b54267481a8d2.tar.gz
Merge ua141d10.elisa.omakaista.fi:/home/my/bk/mysql-4.1
into ua141d10.elisa.omakaista.fi:/home/my/bk/mysql-5.0-tmp heap/_check.c: Auto merged heap/hp_create.c: Auto merged include/config-netware.h: Auto merged include/my_base.h: Auto merged include/my_handler.h: Auto merged include/myisam.h: Auto merged innobase/include/Makefile.am: Auto merged myisam/mi_check.c: Auto merged myisam/mi_delete.c: Auto merged myisam/mi_rnext_same.c: Auto merged myisam/mi_search.c: Auto merged myisam/mi_write.c: Auto merged myisam/myisamdef.h: Auto merged myisam/sort.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/date_formats.result: Auto merged mysql-test/r/update.result: Auto merged mysql-test/t/date_formats.test: Auto merged mysql-test/t/select.test: Auto merged mysql-test/t/update.test: Auto merged mysys/my_getopt.c: Auto merged mysys/my_handler.c: Auto merged scripts/make_binary_distribution.sh: Auto merged sql/ha_myisam.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/records.cc: Auto merged sql/sql_load.cc: Auto merged sql/sql_select.cc: Auto merged sql/structs.h: Auto merged strings/conf_to_src.c: Auto merged strings/ctype-win1250ch.c: Auto merged Makefile.am: Merged from 4.1 myisam/myisamchk.c: Merged from 4.1 mysql-test/mysql-test-run.pl: Merged from 4.1 mysql-test/r/insert_select.result: Merged from 4.1 mysql-test/r/myisam.result: Merged from 4.1 mysql-test/r/select.result: Merged from 4.1 mysql-test/t/insert_select.test: Merged from 4.1 mysql-test/t/myisam.test: Merged from 4.1 netware/mysql_test_run.c: Merged from 4.1 sql/item.cc: Merged from 4.1 sql/mysqld.cc: Merged from 4.1 sql/sql_update.cc: Merged from 4.1 tests/mysql_client_test.c: Merged from 4.1
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_myisam.cc2
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item_timefunc.cc10
-rw-r--r--sql/mysqld.cc17
-rw-r--r--sql/records.cc182
-rw-r--r--sql/sql_load.cc7
-rw-r--r--sql/sql_select.cc1
-rw-r--r--sql/sql_update.cc24
-rw-r--r--sql/structs.h1
9 files changed, 131 insertions, 121 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index ced00c94e73..08fd2d9a8e3 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -40,7 +40,7 @@ TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"",
myisam_recover_names, NULL};
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
- NullS};
+ "nulls_ignored", NullS};
TYPELIB myisam_stats_method_typelib= {
array_elements(myisam_stats_method_names) - 1, "",
myisam_stats_method_names, NULL};
diff --git a/sql/item.cc b/sql/item.cc
index fed3ffcc080..c95b214d36f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5084,8 +5084,15 @@ bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
bool Item_insert_value::fix_fields(THD *thd, Item **items)
{
DBUG_ASSERT(fixed == 0);
+ /* We should only check that arg is in first table */
+ st_table_list *orig_next_table= context->last_name_resolution_table;
+ context->last_name_resolution_table= context->first_name_resolution_table;
if (!arg->fixed && arg->fix_fields(thd, &arg))
+ {
+ context->last_name_resolution_table= orig_next_table;
return TRUE;
+ }
+ context->last_name_resolution_table= orig_next_table;
if (arg->type() == REF_ITEM)
{
@@ -5097,6 +5104,7 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items)
arg= ref->ref[0];
}
Item_field *field_arg= (Item_field *)arg;
+
if (field_arg->field->table->insert_values)
{
Field *def_field= (Field*) sql_alloc(field_arg->field->size_of());
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 459b5a22cb1..4e6087baef9 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1610,6 +1610,16 @@ void Item_func_date_format::fix_length_and_dec()
if (args[1]->type() == STRING_ITEM)
{ // Optimize the normal case
fixed_length=1;
+
+ /*
+ Force case sensitive collation on format string.
+ This needed because format modifiers with different case,
+ for example %m and %M, have different meaning. Thus eq()
+ will distinguish them.
+ */
+ args[1]->collation.set(
+ get_charset_by_csname(args[1]->collation.collation->csname,
+ MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
/*
The result is a binary string (no reason to use collation->mbmaxlen
This is becasue make_date_time() only returns binary strings
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 252fb9c8467..b7d36cc7788 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5608,7 +5608,8 @@ The minimum value for this variable is 4096.",
GET_ULONG, REQUIRED_ARG, 8192*1024, 4, ~0L, 0, 1, 0},
{"myisam_stats_method", OPT_MYISAM_STATS_METHOD,
"Specifies how MyISAM index statistics collection code should threat NULLs. "
- "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), and \"nulls_equal\" (emulate 4.0 behavior).",
+ "Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
+ "\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
(gptr*) &myisam_stats_method_str, (gptr*) &myisam_stats_method_str, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH,
@@ -6863,6 +6864,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
}
case OPT_MYISAM_STATS_METHOD:
{
+ ulong method_conv;
myisam_stats_method_str= argument;
int method;
if ((method=find_type(argument, &myisam_stats_method_typelib, 2)) <= 0)
@@ -6870,7 +6872,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
fprintf(stderr, "Invalid value of myisam_stats_method: %s.\n", argument);
exit(1);
}
- global_system_variables.myisam_stats_method= method-1;
+ switch (method-1) {
+ case 0:
+ method_conv= MI_STATS_METHOD_NULLS_EQUAL;
+ break;
+ case 1:
+ method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
+ break;
+ case 2:
+ method_conv= MI_STATS_METHOD_IGNORE_NULLS;
+ break;
+ }
+ global_system_variables.myisam_stats_method= method_conv;
break;
}
case OPT_SQL_MODE:
diff --git a/sql/records.cc b/sql/records.cc
index 52c3dbdb798..b352f9f395a 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -28,11 +28,10 @@ static int rr_from_pointers(READ_RECORD *info);
static int rr_from_cache(READ_RECORD *info);
static int init_rr_cache(THD *thd, READ_RECORD *info);
static int rr_cmp(uchar *a,uchar *b);
-
+static int rr_index_first(READ_RECORD *info);
static int rr_index(READ_RECORD *info);
-
/*
Initialize READ_RECORD structure to perform full index scan
@@ -58,26 +57,19 @@ void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
bool print_error, uint idx)
{
bzero((char*) info,sizeof(*info));
- info->thd=thd;
- info->table=table;
- info->file= table->file;
- info->forms= &info->table; /* Only one table */
-
+ info->table= table;
+ info->file= table->file;
info->record= table->record[0];
- info->ref_length= table->file->ref_length;
+ info->print_error= print_error;
- info->select=NULL;
- info->print_error=print_error;
- info->ignore_not_found_rows= 0;
table->status=0; /* And it's always found */
-
if (!table->file->inited)
{
table->file->ha_index_init(idx);
table->file->extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY);
}
- info->read_record= rr_index;
- info->first= TRUE;
+ /* read_record will be changed to rr_index in rr_index_first */
+ info->read_record= rr_index_first;
}
@@ -209,6 +201,21 @@ void end_read_record(READ_RECORD *info)
}
}
+static int rr_handle_error(READ_RECORD *info, int error)
+{
+ if (error == HA_ERR_END_OF_FILE)
+ error= -1;
+ else
+ {
+ if (info->print_error)
+ info->table->file->print_error(error, MYF(0));
+ if (error < 0) // Fix negative BDB errno
+ error= 1;
+ }
+ return error;
+}
+
+
/* Read a record from head-database */
static int rr_quick(READ_RECORD *info)
@@ -223,15 +230,7 @@ static int rr_quick(READ_RECORD *info)
}
if (tmp != HA_ERR_RECORD_DELETED)
{
- if (tmp == HA_ERR_END_OF_FILE)
- tmp= -1;
- else
- {
- if (info->print_error)
- info->file->print_error(tmp,MYF(0));
- if (tmp < 0) // Fix negative BDB errno
- tmp=1;
- }
+ tmp= rr_handle_error(info, tmp);
break;
}
}
@@ -240,7 +239,31 @@ static int rr_quick(READ_RECORD *info)
/*
- A READ_RECORD::read_record implementation that reads index sequentially
+ Reads first row in an index scan
+
+ SYNOPSIS
+ rr_index_first()
+ info Scan info
+
+ RETURN
+ 0 Ok
+ -1 End of records
+ 1 Error
+*/
+
+
+static int rr_index_first(READ_RECORD *info)
+{
+ int tmp= info->file->index_first(info->record);
+ info->read_record= rr_index;
+ if (tmp)
+ tmp= rr_handle_error(info, tmp);
+ return tmp;
+}
+
+
+/*
+ Reads index sequentially after first row
SYNOPSIS
rr_index()
@@ -256,43 +279,16 @@ static int rr_quick(READ_RECORD *info)
1 Error
*/
+
static int rr_index(READ_RECORD *info)
{
- int tmp;
- while (1)
- {
- if (info->first)
- {
- info->first= FALSE;
- tmp= info->file->index_first(info->record);
- }
- else
- tmp= info->file->index_next(info->record);
-
- if (!tmp)
- break;
- if (info->thd->killed)
- {
- my_error(ER_SERVER_SHUTDOWN,MYF(0));
- return 1;
- }
- if (tmp != HA_ERR_RECORD_DELETED)
- {
- if (tmp == HA_ERR_END_OF_FILE)
- tmp= -1;
- else
- {
- if (info->print_error)
- info->table->file->print_error(tmp,MYF(0));
- if (tmp < 0) // Fix negative BDB errno
- tmp=1;
- }
- break;
- }
- }
+ int tmp= info->file->index_next(info->record);
+ if (tmp)
+ tmp= rr_handle_error(info, tmp);
return tmp;
}
+
static int rr_sequential(READ_RECORD *info)
{
int tmp;
@@ -303,17 +299,13 @@ static int rr_sequential(READ_RECORD *info)
info->thd->send_kill_message();
return 1;
}
+ /*
+ rnd_next can return RECORD_DELETED for MyISAM when one thread is
+ reading and another deleting without locks.
+ */
if (tmp != HA_ERR_RECORD_DELETED)
{
- if (tmp == HA_ERR_END_OF_FILE)
- tmp= -1;
- else
- {
- if (info->print_error)
- info->table->file->print_error(tmp,MYF(0));
- if (tmp < 0) // Fix negative BDB errno
- tmp=1;
- }
+ tmp= rr_handle_error(info, tmp);
break;
}
}
@@ -324,23 +316,18 @@ static int rr_sequential(READ_RECORD *info)
static int rr_from_tempfile(READ_RECORD *info)
{
int tmp;
-tryNext:
- if (my_b_read(info->io_cache,info->ref_pos,info->ref_length))
- return -1; /* End of file */
- if ((tmp=info->file->rnd_pos(info->record,info->ref_pos)))
+ for (;;)
{
- if (tmp == HA_ERR_END_OF_FILE)
- tmp= -1;
- else if (tmp == HA_ERR_RECORD_DELETED ||
- (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
- goto tryNext;
- else
- {
- if (info->print_error)
- info->file->print_error(tmp,MYF(0));
- if (tmp < 0) // Fix negative BDB errno
- tmp=1;
- }
+ if (my_b_read(info->io_cache,info->ref_pos,info->ref_length))
+ return -1; /* End of file */
+ if (!(tmp=info->file->rnd_pos(info->record,info->ref_pos)))
+ break;
+ /* The following is extremely unlikely to happen */
+ if (tmp == HA_ERR_RECORD_DELETED ||
+ (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
+ continue;
+ tmp= rr_handle_error(info, tmp);
+ break;
}
return tmp;
} /* rr_from_tempfile */
@@ -378,26 +365,23 @@ static int rr_from_pointers(READ_RECORD *info)
{
int tmp;
byte *cache_pos;
-tryNext:
- if (info->cache_pos == info->cache_end)
- return -1; /* End of file */
- cache_pos=info->cache_pos;
- info->cache_pos+=info->ref_length;
- if ((tmp=info->file->rnd_pos(info->record,cache_pos)))
+ for (;;)
{
- if (tmp == HA_ERR_END_OF_FILE)
- tmp= -1;
- else if (tmp == HA_ERR_RECORD_DELETED ||
- (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
- goto tryNext;
- else
- {
- if (info->print_error)
- info->file->print_error(tmp,MYF(0));
- if (tmp < 0) // Fix negative BDB errno
- tmp=1;
- }
+ if (info->cache_pos == info->cache_end)
+ return -1; /* End of file */
+ cache_pos= info->cache_pos;
+ info->cache_pos+= info->ref_length;
+
+ if (!(tmp=info->file->rnd_pos(info->record,cache_pos)))
+ break;
+
+ /* The following is extremely unlikely to happen */
+ if (tmp == HA_ERR_RECORD_DELETED ||
+ (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
+ continue;
+ tmp= rr_handle_error(info, tmp);
+ break;
}
return tmp;
}
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 37342d47d78..568778c021d 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -1026,11 +1026,8 @@ int READ_INFO::read_field()
*to++ = (byte) unescape((char) chr);
continue;
}
- else
- {
- PUSH(chr);
- chr= escape_char;
- }
+ PUSH(chr);
+ chr= escape_char;
}
#ifdef ALLOW_LINESEPARATOR_IN_STRINGS
if (chr == line_term_char)
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 97d5bf4e1d5..44a600be725 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -825,6 +825,7 @@ JOIN::optimize()
{
order=0; // The output has only one row
simple_order=1;
+ select_distinct= 0; // No need in distinct for 1 row
}
calc_group_buffer(this, group_list);
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a8e21177338..620b9676dde 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -244,7 +244,7 @@ int mysql_update(THD *thd,
}
if (!select && limit != HA_POS_ERROR)
{
- if (MAX_KEY != (used_index= get_index_for_order(table, order, limit)))
+ if ((used_index= get_index_for_order(table, order, limit)) != MAX_KEY)
need_sort= FALSE;
}
/* If running in safe sql mode, don't allow updates without keys */
@@ -267,14 +267,14 @@ int mysql_update(THD *thd,
used_key_is_modified= (!select->quick->unique_key_range() &&
select->quick->check_if_keys_used(&fields));
}
- else if (used_index != MAX_KEY)
+ else
{
- used_key_is_modified= check_if_key_used(table, used_index, fields);
+ used_key_is_modified= 0;
+ if (used_index == MAX_KEY) // no index for sort order
+ used_index= table->file->key_used_on_scan;
+ if (used_index != MAX_KEY)
+ used_key_is_modified= check_if_key_used(table, used_index, fields);
}
- else if ((used_index=table->file->key_used_on_scan) < MAX_KEY)
- used_key_is_modified=check_if_key_used(table, used_index, fields);
- else
- used_key_is_modified=0;
if (used_key_is_modified || order)
{
@@ -286,11 +286,11 @@ int mysql_update(THD *thd,
if (used_index < MAX_KEY && old_used_keys.is_set(used_index))
{
table->key_read=1;
- table->file->extra(HA_EXTRA_KEYREAD); //todo: psergey: check
+ table->file->extra(HA_EXTRA_KEYREAD);
}
/* note: can actually avoid sorting below.. */
- if (order && need_sort)
+ if (order && (need_sort || used_key_is_modified))
{
/*
Doing an ORDER BY; Let filesort find and sort the rows we are going
@@ -300,6 +300,7 @@ int mysql_update(THD *thd,
SORT_FIELD *sortorder;
ha_rows examined_rows;
+ used_index= MAX_KEY; // For call to init_read_record()
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
if (!(sortorder=make_unireg_sortorder(order, &length)) ||
@@ -366,10 +367,7 @@ int mysql_update(THD *thd,
error= 1; // Aborted
limit= tmp_limit;
end_read_record(&info);
-
- /* if we got here we must not use index in the main update loop below */
- used_index= MAX_KEY;
-
+
/* Change select to use tempfile */
if (select)
{
diff --git a/sql/structs.h b/sql/structs.h
index 92f09385d6e..21aaf584925 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -135,7 +135,6 @@ typedef struct st_read_record { /* Parameter to read_record */
byte *cache,*cache_pos,*cache_end,*read_positions;
IO_CACHE *io_cache;
bool print_error, ignore_not_found_rows;
- bool first; /* used only with rr_index_read */
} READ_RECORD;