Commit 87b10aed authored by unknown's avatar unknown

Merge kboortz@bk-internal.mysql.com:/home/bk/mysql-4.1

into mysql.com:/Users/kent/mysql/bk/mysql-4.1
parents 48876aee c12bacd3
......@@ -993,13 +993,13 @@ static int read_lines(bool execute_commands)
unsigned long clen;
do
{
line= my_cgets(tmpbuf.c_ptr(), tmpbuf.alloced_length(), &clen);
line= my_cgets(tmpbuf.ptr(), tmpbuf.alloced_length()-1, &clen);
buffer.append(line, clen);
/*
if we got buffer fully filled than there is a chance that
something else is still in console input buffer
*/
} while (tmpbuf.alloced_length() <= clen + 1);
} while (tmpbuf.alloced_length() <= clen);
line= buffer.c_ptr();
#else /* OS2 */
buffer.length(0);
......
......@@ -427,9 +427,9 @@ int init_embedded_server(int argc, char **argv, char **groups)
acl_error= 0;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!(acl_error= acl_init((THD *)0, opt_noacl)) &&
if (!(acl_error= acl_init(opt_noacl)) &&
!opt_noacl)
(void) grant_init((THD *)0);
(void) grant_init();
#endif
if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
{
......
......@@ -40,12 +40,12 @@ void _mi_print_key(FILE *stream, register HA_KEYSEG *keyseg,
end= key+ keyseg->length;
if (keyseg->flag & HA_NULL_PART)
{
if (!*key)
/* A NULL value is encoded by a 1-byte flag. Zero means NULL. */
if (! *(key++))
{
fprintf(stream,"NULL");
continue;
}
key++;
}
switch (keyseg->type) {
......
......@@ -31,8 +31,8 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
HA_KEYSEG *last_used_keyseg;
uint pack_key_length, use_key_length, nextflag;
DBUG_ENTER("mi_rkey");
DBUG_PRINT("enter",("base: %lx inx: %d search_flag: %d",
info,inx,search_flag));
DBUG_PRINT("enter", ("base: %p buf: %p inx: %d search_flag: %d",
info, buf, inx, search_flag));
if ((inx = _mi_check_index(info,inx)) < 0)
DBUG_RETURN(my_errno);
......@@ -56,9 +56,12 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
{
if (key_len == 0)
key_len=USE_WHOLE_KEY;
/* Save the packed key for later use in the second buffer of lastkey. */
key_buff=info->lastkey+info->s->base.max_key_length;
pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key,
key_len, &last_used_keyseg);
/* Save packed_key_length for use by the MERGE engine. */
info->pack_key_length= pack_key_length;
DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg,
key_buff, pack_key_length););
}
......
......@@ -908,11 +908,21 @@ uint _mi_get_binary_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
reg1 HA_KEYSEG *keyseg;
uchar *start_key,*page,*page_end,*from,*from_end;
uint length,tmp;
DBUG_ENTER("_mi_get_binary_pack_key");
page= *page_pos;
page_end=page+MI_MAX_KEY_BUFF+1;
start_key=key;
/*
Keys are compressed the following way:
prefix length Packed length of prefix for the prev key. (1 or 3 bytes)
for each key segment:
[is null] Null indicator if can be null (1 byte, zero means null)
[length] Packed length if varlength (1 or 3 bytes)
pointer Reference to the data file (last_keyseg->length).
*/
get_key_length(length,page);
if (length)
{
......@@ -922,7 +932,7 @@ uint _mi_get_binary_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
length, keyinfo->maxlength, *page_pos));
DBUG_DUMP("key",(char*) *page_pos,16);
my_errno=HA_ERR_CRASHED;
return 0; /* Wrong key */
DBUG_RETURN(0); /* Wrong key */
}
from=key; from_end=key+length;
}
......@@ -983,12 +993,12 @@ uint _mi_get_binary_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
{
DBUG_PRINT("error",("Error when unpacking key"));
my_errno=HA_ERR_CRASHED;
return 0; /* Error */
DBUG_RETURN(0); /* Error */
}
memcpy((byte*) key,(byte*) from,(size_t) length);
*page_pos= from+length;
}
return((uint) (key-start_key)+keyseg->length);
DBUG_RETURN((uint) (key-start_key)+keyseg->length);
}
......
......@@ -261,6 +261,7 @@ struct st_myisam_info {
uint last_rkey_length; /* Last length in mi_rkey() */
enum ha_rkey_function last_key_func; /* CONTAIN, OVERLAP, etc */
uint save_lastkey_length;
uint pack_key_length; /* For MYISAMMRG */
int errkey; /* Got last error on this key */
int lock_type; /* How database was locked */
int tmp_lock_type; /* When locked by readinfo */
......
......@@ -44,11 +44,12 @@ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key,
MYRG_TABLE *table;
MI_INFO *mi;
int err;
DBUG_ENTER("myrg_rkey");
LINT_INIT(key_buff);
LINT_INIT(pack_key_length);
if (_myrg_init_queue(info,inx,search_flag))
return my_errno;
DBUG_RETURN(my_errno);
for (table=info->open_tables ; table != info->end_table ; table++)
{
......@@ -57,8 +58,9 @@ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key,
if (table == info->open_tables)
{
err=mi_rkey(mi,0,inx,key,key_len,search_flag);
/* Get the saved packed key and packed key length. */
key_buff=(byte*) mi->lastkey+mi->s->base.max_key_length;
pack_key_length=mi->last_rkey_length;
pack_key_length=mi->pack_key_length;
}
else
{
......@@ -71,17 +73,22 @@ int myrg_rkey(MYRG_INFO *info,byte *buf,int inx, const byte *key,
{
if (err == HA_ERR_KEY_NOT_FOUND)
continue;
return err;
DBUG_PRINT("exit", ("err: %d", err));
DBUG_RETURN(err);
}
/* adding to queue */
queue_insert(&(info->by_key),(byte *)table);
}
DBUG_PRINT("info", ("tables with matches: %u", info->by_key.elements));
if (!info->by_key.elements)
return HA_ERR_KEY_NOT_FOUND;
DBUG_RETURN(HA_ERR_KEY_NOT_FOUND);
mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table;
mi->once_flags|= RRND_PRESERVE_LASTINX;
return _myrg_mi_read_record(mi,buf);
DBUG_PRINT("info", ("using table no: %d",
info->current_table - info->open_tables + 1));
DBUG_DUMP("result key", (byte*) mi->lastkey, mi->lastkey_length);
DBUG_RETURN(_myrg_mi_read_record(mi,buf));
}
......@@ -54,6 +54,18 @@ CONVERT(DATE "2004-01-22 21:45:33",BINARY(4))
select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4));
CAST(DATE "2004-01-22 21:45:33" AS BINARY(4))
2004
select CAST(0xb3 as signed);
CAST(0xb3 as signed)
179
select CAST(0x8fffffffffffffff as signed);
CAST(0x8fffffffffffffff as signed)
-8070450532247928833
select CAST(0xffffffffffffffff as unsigned);
CAST(0xffffffffffffffff as unsigned)
18446744073709551615
select CAST(0xfffffffffffffffe as signed);
CAST(0xfffffffffffffffe as signed)
-2
select cast('18446744073709551616' as unsigned);
cast('18446744073709551616' as unsigned)
18446744073709551615
......
......@@ -651,6 +651,32 @@ ERROR HY000: You can't specify target table 't1' for update in FROM clause
create table t3 engine=merge union=(t1, t2) select * from t2;
ERROR HY000: You can't specify target table 't2' for update in FROM clause
drop table t1, t2;
create table t1 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=merge union=(t2,t3);
create table t2 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=myisam;
create table t3 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=myisam;
insert into t2 values ( null, '');
insert into t2 values ( 9999999999.999999, '');
insert into t3 select * from t2;
select min(a), max(a) from t1;
min(a) max(a)
9999999999.999998 9999999999.999998
flush tables;
select min(a), max(a) from t1;
min(a) max(a)
9999999999.999998 9999999999.999998
drop table t1, t2, t3;
create table t1 (a int,b int,c int, index (a,b,c));
create table t2 (a int,b int,c int, index (a,b,c));
create table t3 (a int,b int,c int, index (a,b,c))
......
......@@ -2617,3 +2617,12 @@ select found_rows();
found_rows()
1
DROP TABLE t1;
create table t1(f1 int, f2 int);
create table t2(f3 int);
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1));
f1
select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1));
f1
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL));
f1
drop table t1,t2;
......@@ -286,6 +286,42 @@ create table t3 engine=merge union=(t1, t2) select * from t1;
create table t3 engine=merge union=(t1, t2) select * from t2;
drop table t1, t2;
#
# Bug#9112 - Merge table with composite index producing invalid results with some queries
# This test case will fail only without the bugfix and some
# non-deterministic circumstances. It depends on properly initialized
# "un-initialized" memory. At the time it happens with a standard
# non-debug build. But there is no guarantee that this will be always so.
#
create table t1 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=merge union=(t2,t3);
create table t2 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=myisam;
create table t3 (
a double(16,6),
b varchar(10),
index (a,b)
) engine=myisam;
insert into t2 values ( null, '');
# We may have insufficient accuracy for 16 digits of '9'.
# Suppress a "truncate" warning due to accuracy problems.
--disable_warnings
insert into t2 values ( 9999999999.999999, '');
--enable_warnings
insert into t3 select * from t2;
select min(a), max(a) from t1;
flush tables;
select min(a), max(a) from t1;
drop table t1, t2, t3;
# BUG#6699 : no sorting on 'ref' retrieval
create table t1 (a int,b int,c int, index (a,b,c));
create table t2 (a int,b int,c int, index (a,b,c));
......
......@@ -2164,4 +2164,14 @@ select found_rows();
DROP TABLE t1;
#
# Bug #13356 assertion failed in resolve_const_item()
#
create table t1(f1 int, f2 int);
create table t2(f3 int);
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1));
select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1));
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL));
drop table t1,t2;
# End of 4.1 tests
#SUBDIRS = printSchemafile
noinst_LIBRARIES = libdbdict.a
EXTRA_PROGRAMS = printSchemaFile
libdbdict_a_SOURCES = Dbdict.cpp
printSchemaFile_SOURCES = printSchemaFile.cpp
include $(top_srcdir)/ndb/config/common.mk.am
include $(top_srcdir)/ndb/config/type_kernel.mk.am
LDADD += \
$(top_builddir)/ndb/src/common/util/libgeneral.la \
$(top_builddir)/ndb/src/common/portlib/libportlib.la \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/mysys/libmysys.a \
$(top_builddir)/strings/libmystrings.a
# Don't update the files from bitkeeper
%::SCCS/s.%
......
#if 0
make -f Makefile -f - printSchemaFile <<'_eof_'
printSchemaFile: printSchemaFile.cpp
$(CXXCOMPILE) -o $@ $@.cpp -L../../../common/util/.libs -lgeneral
_eof_
exit $?
#endif
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
......@@ -58,8 +50,7 @@ print(const char * filename, const SchemaFile * file){
SchemaFile::TableEntry te = file->TableEntries[i];
if(te.m_tableState != SchemaFile::INIT){
ndbout << "Table " << i << ": State = " << te.m_tableState
<< " version = " << table_version_major(te.m_tableVersion) <<
<< "(" << table_version_minor(te.m_tableVersion) << ")"
<< " version = " << te.m_tableVersion
<< " type = " << te.m_tableType
<< " noOfPages = " << te.m_noOfPages
<< " gcp: " << te.m_gcp << endl;
......
......@@ -598,8 +598,8 @@ int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field,
blob_ptr= (char*)"";
}
DBUG_PRINT("value", ("set blob ptr=%x len=%u",
(unsigned)blob_ptr, blob_len));
DBUG_PRINT("value", ("set blob ptr=%p len=%u",
blob_ptr, blob_len));
DBUG_DUMP("value", (char*)blob_ptr, min(blob_len, 26));
if (set_blob_value)
......
......@@ -2870,6 +2870,35 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
new_item= (null_value ? (Item*) new Item_null(name) :
(Item*) new Item_int(name, result, length));
}
else if (res_type == ROW_RESULT)
{
new_item= 0;
/*
If item and comp_item are both Item_rows and have same number of cols
then process items in Item_row one by one. If Item_row contain nulls
substitute it by Item_null. Otherwise just return.
*/
if (item->result_type() == comp_item->result_type() &&
((Item_row*)item)->cols() == ((Item_row*)comp_item)->cols())
{
Item_row *item_row= (Item_row*)item,*comp_item_row= (Item_row*)comp_item;
if (item_row->null_inside())
new_item= (Item*) new Item_null(name);
else
{
int i= item_row->cols() - 1;
for (; i >= 0; i--)
{
if (item_row->maybe_null && item_row->el(i)->is_null())
{
new_item= (Item*) new Item_null(name);
break;
}
resolve_const_item(thd, item_row->addr(i), comp_item_row->el(i));
}
}
}
}
else
{ // It must REAL_RESULT
double result=item->val();
......
......@@ -108,7 +108,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
WHERE t2.field IS NULL;
*/
if (tl->table->map & where_tables)
const_result= 0;
return 0;
}
else
used_tables|= tl->table->map;
......@@ -119,7 +119,10 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
may be used as the real count.
*/
if (tl->table->file->table_flags() & HA_NOT_EXACT_COUNT)
{
is_exact_count= FALSE;
count= 1; // ensure count != 0
}
else
{
tl->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
......@@ -127,9 +130,6 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
}
}
if (!const_result)
return 0;
/*
Iterate through all items in the SELECT clause and replace
COUNT(), MIN() and MAX() with constants (if possible).
......@@ -150,8 +150,8 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null &&
!outer_tables && is_exact_count)
{
((Item_sum_count*) item)->make_const(count);
recalc_const_item= 1;
((Item_sum_count*) item)->make_const(count);
recalc_const_item= 1;
}
else
const_result= 0;
......@@ -234,7 +234,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
}
if (!count)
{
/* If count != 1, then we know that is_exact_count == TRUE. */
/* If count == 0, then we know that is_exact_count == TRUE. */
((Item_sum_min*) item_sum)->clear(); /* Set to NULL. */
}
else
......
......@@ -27,8 +27,8 @@
#include "ha_innodb.h"
#include "sql_select.h"
int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order,
ha_rows limit, ulong options)
int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
SQL_LIST *order, ha_rows limit, ulong options)
{
int error;
TABLE *table;
......@@ -266,6 +266,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
select_lex.table_list.first);
DBUG_ENTER("mysql_prepare_delete");
thd->allow_sum_func= 0;
if (setup_conds(thd, delete_table_list, conds) ||
setup_ftfuncs(&thd->lex->select_lex))
DBUG_RETURN(-1);
......
......@@ -160,7 +160,6 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
lex->proc_list.first= 0;
thd->allow_sum_func= 0;
}
void lex_end(LEX *lex)
......
......@@ -429,8 +429,6 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
while ((sql_field= (Item_field*) it++))
{
Field *field= sql_field->field;
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if (pos == read_info.row_end)
{
thd->cuted_fields++; /* Not enough fields */
......@@ -443,11 +441,13 @@ read_fixed_length(THD *thd,COPY_INFO &info,TABLE *table,List<Item> &fields,
{
uint length;
byte save_chr;
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if ((length=(uint) (read_info.row_end-pos)) >
field->field_length)
length=field->field_length;
save_chr=pos[length]; pos[length]='\0'; // Safeguard aganst malloc
field->store((char*) pos,length,read_info.read_charset);
field->store((char*) pos,length,read_info.read_charset);
pos[length]=save_chr;
if ((pos+=length) > read_info.row_end)
pos= read_info.row_end; /* Fills rest with space */
......@@ -522,8 +522,6 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
length=(uint) (read_info.row_end-pos);
Field *field=sql_field->field;
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if (!read_info.enclosed &&
(enclosed_length && length == 4 && !memcmp(pos,"NULL",4)) ||
(length == 1 && read_info.found_null))
......@@ -540,6 +538,8 @@ read_sep_field(THD *thd,COPY_INFO &info,TABLE *table,
}
continue;
}
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
field->set_notnull();
read_info.row_end[0]=0; // Safe to change end marker
field->store((char*) read_info.row_start,length,read_info.read_charset);
......
......@@ -1738,7 +1738,6 @@ static void reset_stmt_for_execute(Prepared_statement *stmt)
lex->current_select= &lex->select_lex;
if (lex->result)
lex->result->cleanup();
thd->allow_sum_func= 0;
}
......
......@@ -426,6 +426,7 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
bzero((char*) &tables,sizeof(tables)); // For ORDER BY
tables.table= table;
tables.alias= table_list->alias;
thd->allow_sum_func= 0;
if (setup_tables(update_table_list) ||
setup_conds(thd, update_table_list, conds) ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment