Commit a12b0b28 authored by unknown's avatar unknown

Merge abarkov@bk-internal.mysql.com:/home/bk/mysql-5.0

into mysql.com:/home/bar/mysql-5.0

parents 52740354 e7eac027
...@@ -71,6 +71,7 @@ hf@deer.(none) ...@@ -71,6 +71,7 @@ hf@deer.(none)
hf@deer.mysql.r18.ru hf@deer.mysql.r18.ru
hf@genie.(none) hf@genie.(none)
igor@hundin.mysql.fi igor@hundin.mysql.fi
igor@linux.local
igor@rurik.mysql.com igor@rurik.mysql.com
ingo@mysql.com ingo@mysql.com
jan@hundin.mysql.fi jan@hundin.mysql.fi
......
...@@ -262,6 +262,20 @@ trx_free( ...@@ -262,6 +262,20 @@ trx_free(
putc('\n', stderr); putc('\n', stderr);
} }
if (trx->n_mysql_tables_in_use != 0
|| trx->mysql_n_tables_locked != 0) {
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Error: MySQL is freeing a thd\n"
"InnoDB: though trx->n_mysql_tables_in_use is %lu\n"
"InnoDB: and trx->mysql_n_tables_locked is %lu.\n",
(ulong)trx->n_mysql_tables_in_use,
(ulong)trx->mysql_n_tables_locked);
trx_print(stderr, trx);
}
ut_a(trx->magic_n == TRX_MAGIC_N); ut_a(trx->magic_n == TRX_MAGIC_N);
trx->magic_n = 11112222; trx->magic_n = 11112222;
...@@ -272,9 +286,6 @@ trx_free( ...@@ -272,9 +286,6 @@ trx_free(
ut_a(trx->insert_undo == NULL); ut_a(trx->insert_undo == NULL);
ut_a(trx->update_undo == NULL); ut_a(trx->update_undo == NULL);
ut_a(trx->n_mysql_tables_in_use == 0);
ut_a(trx->mysql_n_tables_locked == 0);
if (trx->undo_no_arr) { if (trx->undo_no_arr) {
trx_undo_arr_free(trx->undo_no_arr); trx_undo_arr_free(trx->undo_no_arr);
......
...@@ -14,6 +14,7 @@ Created 5/11/1994 Heikki Tuuri ...@@ -14,6 +14,7 @@ Created 5/11/1994 Heikki Tuuri
#include "mem0mem.h" #include "mem0mem.h"
#include "os0sync.h" #include "os0sync.h"
#include "os0thread.h"
/* This struct is placed first in every allocated memory block */ /* This struct is placed first in every allocated memory block */
typedef struct ut_mem_block_struct ut_mem_block_t; typedef struct ut_mem_block_struct ut_mem_block_t;
...@@ -66,6 +67,7 @@ ut_malloc_low( ...@@ -66,6 +67,7 @@ ut_malloc_low(
ibool assert_on_error) /* in: if TRUE, we crash mysqld if the memory ibool assert_on_error) /* in: if TRUE, we crash mysqld if the memory
cannot be allocated */ cannot be allocated */
{ {
ulint retry_count = 0;
void* ret; void* ret;
ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */ ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
...@@ -73,24 +75,26 @@ ut_malloc_low( ...@@ -73,24 +75,26 @@ ut_malloc_low(
if (!ut_mem_block_list_inited) { if (!ut_mem_block_list_inited) {
ut_mem_block_list_init(); ut_mem_block_list_init();
} }
retry:
os_fast_mutex_lock(&ut_list_mutex); os_fast_mutex_lock(&ut_list_mutex);
ret = malloc(n + sizeof(ut_mem_block_t)); ret = malloc(n + sizeof(ut_mem_block_t));
if (ret == NULL) { if (ret == NULL && retry_count < 60) {
ut_print_timestamp(stderr); if (retry_count == 0) {
fprintf(stderr, ut_print_timestamp(stderr);
" InnoDB: Fatal error: cannot allocate %lu bytes of\n"
fprintf(stderr,
" InnoDB: Error: cannot allocate %lu bytes of\n"
"InnoDB: memory with malloc! Total allocated memory\n" "InnoDB: memory with malloc! Total allocated memory\n"
"InnoDB: by InnoDB %lu bytes. Operating system errno: %lu\n" "InnoDB: by InnoDB %lu bytes. Operating system errno: %lu\n"
"InnoDB: Cannot continue operation!\n"
"InnoDB: Check if you should increase the swap file or\n" "InnoDB: Check if you should increase the swap file or\n"
"InnoDB: ulimits of your operating system.\n" "InnoDB: ulimits of your operating system.\n"
"InnoDB: On FreeBSD check you have compiled the OS with\n" "InnoDB: On FreeBSD check you have compiled the OS with\n"
"InnoDB: a big enough maximum process size.\n" "InnoDB: a big enough maximum process size.\n"
"InnoDB: Note that in most 32-bit computers the process\n" "InnoDB: Note that in most 32-bit computers the process\n"
"InnoDB: memory space is limited to 2 GB or 4 GB.\n", "InnoDB: memory space is limited to 2 GB or 4 GB.\n",
"InnoDB: We keep retrying the allocation for 60 seconds...\n",
(ulong) n, (ulong) ut_total_allocated_memory, (ulong) n, (ulong) ut_total_allocated_memory,
#ifdef __WIN__ #ifdef __WIN__
(ulong) GetLastError() (ulong) GetLastError()
...@@ -98,7 +102,21 @@ ut_malloc_low( ...@@ -98,7 +102,21 @@ ut_malloc_low(
(ulong) errno (ulong) errno
#endif #endif
); );
}
os_fast_mutex_unlock(&ut_list_mutex);
/* Sleep for a second and retry the allocation; maybe this is
just a temporary shortage of memory */
os_thread_sleep(1000000);
retry_count++;
goto retry;
}
if (ret == NULL) {
/* Flush stderr to make more probable that the error /* Flush stderr to make more probable that the error
message gets in the error file before we generate a seg message gets in the error file before we generate a seg
fault */ fault */
...@@ -113,8 +131,10 @@ ut_malloc_low( ...@@ -113,8 +131,10 @@ ut_malloc_low(
by graceful exit handling in ut_a(). */ by graceful exit handling in ut_a(). */
#if (!defined __NETWARE__) #if (!defined __NETWARE__)
if (assert_on_error) { if (assert_on_error) {
ut_print_timestamp(stderr);
fprintf(stderr, fprintf(stderr,
"InnoDB: We now intentionally generate a seg fault so that\n" " InnoDB: We now intentionally generate a seg fault so that\n"
"InnoDB: on Linux we get a stack trace.\n"); "InnoDB: on Linux we get a stack trace.\n");
if (*ut_mem_null_ptr) ut_mem_null_ptr = 0; if (*ut_mem_null_ptr) ut_mem_null_ptr = 0;
......
...@@ -514,7 +514,7 @@ Variable_name Value ...@@ -514,7 +514,7 @@ Variable_name Value
character_set_client latin1 character_set_client latin1
SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; SELECT charset('a'),collation('a'),coercibility('a'),'a'='A';
charset('a') collation('a') coercibility('a') 'a'='A' charset('a') collation('a') coercibility('a') 'a'='A'
latin1 latin1_swedish_ci 3 1 latin1 latin1_swedish_ci 4 1
explain extended SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; explain extended SELECT charset('a'),collation('a'),coercibility('a'),'a'='A';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
...@@ -525,7 +525,7 @@ SHOW VARIABLES LIKE 'collation_client'; ...@@ -525,7 +525,7 @@ SHOW VARIABLES LIKE 'collation_client';
Variable_name Value Variable_name Value
SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; SELECT charset('a'),collation('a'),coercibility('a'),'a'='A';
charset('a') collation('a') coercibility('a') 'a'='A' charset('a') collation('a') coercibility('a') 'a'='A'
latin1 latin1_swedish_ci 3 1 latin1 latin1_swedish_ci 4 1
SET CHARACTER SET 'DEFAULT'; SET CHARACTER SET 'DEFAULT';
ERROR 42000: Unknown character set: 'DEFAULT' ERROR 42000: Unknown character set: 'DEFAULT'
DROP TABLE t1; DROP TABLE t1;
......
...@@ -831,4 +831,29 @@ select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(va ...@@ -831,4 +831,29 @@ select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(va
id stddev_pop(value1) var_pop(value1) stddev_samp(value1) var_samp(value1) id stddev_pop(value1) var_pop(value1) stddev_samp(value1) var_samp(value1)
1 0.816497 0.666667 1.000000 1.000000 1 0.816497 0.666667 1.000000 1.000000
2 1.118034 1.250000 1.290994 1.666667 2 1.118034 1.250000 1.290994 1.666667
CREATE TABLE t1(
id int PRIMARY KEY,
a int,
b int,
INDEX i_b_id(a,b,id),
INDEX i_id(a,id)
);
INSERT INTO t1 VALUES
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
MAX(id)
NULL
DROP TABLE t1;
CREATE TABLE t1(
id int PRIMARY KEY,
a int,
b int,
INDEX i_id(a,id),
INDEX i_b_id(a,b,id)
);
INSERT INTO t1 VALUES
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
MAX(id)
NULL
DROP TABLE t1; DROP TABLE t1;
...@@ -693,6 +693,277 @@ show warnings; ...@@ -693,6 +693,277 @@ show warnings;
Level Code Message Level Code Message
Warning 1264 Out of range value adjusted for column 'c1' at row 1 Warning 1264 Out of range value adjusted for column 'c1' at row 1
Warning 1264 Out of range value adjusted for column 'c2' at row 1 Warning 1264 Out of range value adjusted for column 'c2' at row 1
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT) and (latin1_bin,EXPLICIT) for operation 'substr_index'
select _latin1'B' between _latin1'a' and _latin1'c';
_latin1'B' between _latin1'a' and _latin1'c'
1
select _latin1'B' collate latin1_bin between _latin1'a' and _latin1'c';
_latin1'B' collate latin1_bin between _latin1'a' and _latin1'c'
0
select _latin1'B' between _latin1'a' collate latin1_bin and _latin1'c';
_latin1'B' between _latin1'a' collate latin1_bin and _latin1'c'
0
select _latin1'B' between _latin1'a' and _latin1'c' collate latin1_bin;
_latin1'B' between _latin1'a' and _latin1'c' collate latin1_bin
0
select _latin2'B' between _latin1'a' and _latin1'b';
ERROR HY000: Illegal mix of collations (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation 'between'
select _latin1'B' between _latin2'a' and _latin1'b';
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation 'between'
select _latin1'B' between _latin1'a' and _latin2'b';
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE) for operation 'between'
select _latin1'B' collate latin1_general_ci between _latin1'a' collate latin1_bin and _latin1'b';
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_bin,EXPLICIT), (latin1_swedish_ci,COERCIBLE) for operation 'between'
select _latin1'B' in (_latin1'a',_latin1'b');
_latin1'B' in (_latin1'a',_latin1'b')
1
select _latin1'B' collate latin1_bin in (_latin1'a',_latin1'b');
_latin1'B' collate latin1_bin in (_latin1'a',_latin1'b')
0
select _latin1'B' in (_latin1'a' collate latin1_bin,_latin1'b');
_latin1'B' in (_latin1'a' collate latin1_bin,_latin1'b')
0
select _latin1'B' in (_latin1'a',_latin1'b' collate latin1_bin);
_latin1'B' in (_latin1'a',_latin1'b' collate latin1_bin)
0
select _latin2'B' in (_latin1'a',_latin1'b');
ERROR HY000: Illegal mix of collations (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation ' IN '
select _latin1'B' in (_latin2'a',_latin1'b');
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation ' IN '
select _latin1'B' in (_latin1'a',_latin2'b');
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE) for operation ' IN '
select _latin1'B' COLLATE latin1_general_ci in (_latin1'a' COLLATE latin1_bin,_latin1'b');
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_bin,EXPLICIT), (latin1_swedish_ci,COERCIBLE) for operation ' IN '
select _latin1'B' COLLATE latin1_general_ci in (_latin1'a',_latin1'b' COLLATE latin1_bin);
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_swedish_ci,COERCIBLE), (latin1_bin,EXPLICIT) for operation ' IN '
select collation(bin(130)), coercibility(bin(130));
collation(bin(130)) coercibility(bin(130))
latin1_swedish_ci 4
select collation(oct(130)), coercibility(oct(130));
collation(oct(130)) coercibility(oct(130))
latin1_swedish_ci 4
select collation(conv(130,16,10)), coercibility(conv(130,16,10));
collation(conv(130,16,10)) coercibility(conv(130,16,10))
latin1_swedish_ci 4
select collation(hex(130)), coercibility(hex(130));
collation(hex(130)) coercibility(hex(130))
latin1_swedish_ci 4
select collation(char(130)), coercibility(hex(130));
collation(char(130)) coercibility(hex(130))
latin1_swedish_ci 4
select collation(format(130,10)), coercibility(format(130,10));
collation(format(130,10)) coercibility(format(130,10))
latin1_swedish_ci 4
select collation(lcase(_latin2'a')), coercibility(lcase(_latin2'a'));
collation(lcase(_latin2'a')) coercibility(lcase(_latin2'a'))
latin2_general_ci 4
select collation(ucase(_latin2'a')), coercibility(ucase(_latin2'a'));
collation(ucase(_latin2'a')) coercibility(ucase(_latin2'a'))
latin2_general_ci 4
select collation(left(_latin2'a',1)), coercibility(left(_latin2'a',1));
collation(left(_latin2'a',1)) coercibility(left(_latin2'a',1))
latin2_general_ci 4
select collation(right(_latin2'a',1)), coercibility(right(_latin2'a',1));
collation(right(_latin2'a',1)) coercibility(right(_latin2'a',1))
latin2_general_ci 4
select collation(substring(_latin2'a',1,1)), coercibility(substring(_latin2'a',1,1));
collation(substring(_latin2'a',1,1)) coercibility(substring(_latin2'a',1,1))
latin2_general_ci 4
select collation(concat(_latin2'a',_latin2'b')), coercibility(concat(_latin2'a',_latin2'b'));
collation(concat(_latin2'a',_latin2'b')) coercibility(concat(_latin2'a',_latin2'b'))
latin2_general_ci 4
select collation(lpad(_latin2'a',4,_latin2'b')), coercibility(lpad(_latin2'a',4,_latin2'b'));
collation(lpad(_latin2'a',4,_latin2'b')) coercibility(lpad(_latin2'a',4,_latin2'b'))
latin2_general_ci 4
select collation(rpad(_latin2'a',4,_latin2'b')), coercibility(rpad(_latin2'a',4,_latin2'b'));
collation(rpad(_latin2'a',4,_latin2'b')) coercibility(rpad(_latin2'a',4,_latin2'b'))
latin2_general_ci 4
select collation(concat_ws(_latin2'a',_latin2'b')), coercibility(concat_ws(_latin2'a',_latin2'b'));
collation(concat_ws(_latin2'a',_latin2'b')) coercibility(concat_ws(_latin2'a',_latin2'b'))
latin2_general_ci 4
select collation(make_set(255,_latin2'a',_latin2'b',_latin2'c')), coercibility(make_set(255,_latin2'a',_latin2'b',_latin2'c'));
collation(make_set(255,_latin2'a',_latin2'b',_latin2'c')) coercibility(make_set(255,_latin2'a',_latin2'b',_latin2'c'))
latin2_general_ci 4
select collation(export_set(255,_latin2'y',_latin2'n',_latin2' ')), coercibility(export_set(255,_latin2'y',_latin2'n',_latin2' '));
collation(export_set(255,_latin2'y',_latin2'n',_latin2' ')) coercibility(export_set(255,_latin2'y',_latin2'n',_latin2' '))
binary 4
select collation(trim(_latin2' a ')), coercibility(trim(_latin2' a '));
collation(trim(_latin2' a ')) coercibility(trim(_latin2' a '))
latin2_general_ci 4
select collation(ltrim(_latin2' a ')), coercibility(ltrim(_latin2' a '));
collation(ltrim(_latin2' a ')) coercibility(ltrim(_latin2' a '))
latin2_general_ci 4
select collation(rtrim(_latin2' a ')), coercibility(rtrim(_latin2' a '));
collation(rtrim(_latin2' a ')) coercibility(rtrim(_latin2' a '))
latin2_general_ci 4
select collation(trim(LEADING _latin2' ' FROM _latin2'a')), coercibility(trim(LEADING _latin2'a' FROM _latin2'a'));
collation(trim(LEADING _latin2' ' FROM _latin2'a')) coercibility(trim(LEADING _latin2'a' FROM _latin2'a'))
latin2_general_ci 4
select collation(trim(TRAILING _latin2' ' FROM _latin2'a')), coercibility(trim(TRAILING _latin2'a' FROM _latin2'a'));
collation(trim(TRAILING _latin2' ' FROM _latin2'a')) coercibility(trim(TRAILING _latin2'a' FROM _latin2'a'))
latin2_general_ci 4
select collation(trim(BOTH _latin2' ' FROM _latin2'a')), coercibility(trim(BOTH _latin2'a' FROM _latin2'a'));
collation(trim(BOTH _latin2' ' FROM _latin2'a')) coercibility(trim(BOTH _latin2'a' FROM _latin2'a'))
latin2_general_ci 4
select collation(repeat(_latin2'a',10)), coercibility(repeat(_latin2'a',10));
collation(repeat(_latin2'a',10)) coercibility(repeat(_latin2'a',10))
latin2_general_ci 4
select collation(reverse(_latin2'ab')), coercibility(reverse(_latin2'ab'));
collation(reverse(_latin2'ab')) coercibility(reverse(_latin2'ab'))
latin2_general_ci 4
select collation(quote(_latin2'ab')), coercibility(quote(_latin2'ab'));
collation(quote(_latin2'ab')) coercibility(quote(_latin2'ab'))
latin2_general_ci 4
select collation(soundex(_latin2'ab')), coercibility(soundex(_latin2'ab'));
collation(soundex(_latin2'ab')) coercibility(soundex(_latin2'ab'))
latin2_general_ci 4
select collation(substring(_latin2'ab',1)), coercibility(substring(_latin2'ab',1));
collation(substring(_latin2'ab',1)) coercibility(substring(_latin2'ab',1))
latin2_general_ci 4
select collation(insert(_latin2'abcd',2,3,_latin2'ef')), coercibility(insert(_latin2'abcd',2,3,_latin2'ef'));
collation(insert(_latin2'abcd',2,3,_latin2'ef')) coercibility(insert(_latin2'abcd',2,3,_latin2'ef'))
latin2_general_ci 4
select collation(replace(_latin2'abcd',_latin2'b',_latin2'B')), coercibility(replace(_latin2'abcd',_latin2'b',_latin2'B'));
collation(replace(_latin2'abcd',_latin2'b',_latin2'B')) coercibility(replace(_latin2'abcd',_latin2'b',_latin2'B'))
latin2_general_ci 4
select collation(encode('abcd','ab')), coercibility(encode('abcd','ab'));
collation(encode('abcd','ab')) coercibility(encode('abcd','ab'))
binary 4
create table t1
select
bin(130),
oct(130),
conv(130,16,10),
hex(130),
char(130),
format(130,10),
left(_latin2'a',1),
right(_latin2'a',1),
lcase(_latin2'a'),
ucase(_latin2'a'),
substring(_latin2'a',1,1),
concat(_latin2'a',_latin2'b'),
lpad(_latin2'a',4,_latin2'b'),
rpad(_latin2'a',4,_latin2'b'),
concat_ws(_latin2'a',_latin2'b'),
make_set(255,_latin2'a',_latin2'b',_latin2'c'),
export_set(255,_latin2'y',_latin2'n',_latin2' '),
trim(_latin2' a '),
ltrim(_latin2' a '),
rtrim(_latin2' a '),
trim(LEADING _latin2' ' FROM _latin2' a '),
trim(TRAILING _latin2' ' FROM _latin2' a '),
trim(BOTH _latin2' ' FROM _latin2' a '),
repeat(_latin2'a',10),
reverse(_latin2'ab'),
quote(_latin2'ab'),
soundex(_latin2'ab'),
substring(_latin2'ab',1),
insert(_latin2'abcd',2,3,_latin2'ef'),
replace(_latin2'abcd',_latin2'b',_latin2'B'),
encode('abcd','ab')
;
Warnings:
Warning 1265 Data truncated for column 'format(130,10)' at row 1
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`bin(130)` char(64) NOT NULL default '',
`oct(130)` char(64) NOT NULL default '',
`conv(130,16,10)` char(64) NOT NULL default '',
`hex(130)` char(6) NOT NULL default '',
`char(130)` char(1) NOT NULL default '',
`format(130,10)` char(4) NOT NULL default '',
`left(_latin2'a',1)` char(1) character set latin2 NOT NULL default '',
`right(_latin2'a',1)` char(1) character set latin2 NOT NULL default '',
`lcase(_latin2'a')` char(1) character set latin2 NOT NULL default '',
`ucase(_latin2'a')` char(1) character set latin2 NOT NULL default '',
`substring(_latin2'a',1,1)` char(1) character set latin2 NOT NULL default '',
`concat(_latin2'a',_latin2'b')` char(2) character set latin2 NOT NULL default '',
`lpad(_latin2'a',4,_latin2'b')` char(4) character set latin2 NOT NULL default '',
`rpad(_latin2'a',4,_latin2'b')` char(4) character set latin2 NOT NULL default '',
`concat_ws(_latin2'a',_latin2'b')` char(1) character set latin2 NOT NULL default '',
`make_set(255,_latin2'a',_latin2'b',_latin2'c')` char(5) character set latin2 NOT NULL default '',
`export_set(255,_latin2'y',_latin2'n',_latin2' ')` char(127) character set latin2 NOT NULL default '',
`trim(_latin2' a ')` char(3) character set latin2 NOT NULL default '',
`ltrim(_latin2' a ')` char(3) character set latin2 NOT NULL default '',
`rtrim(_latin2' a ')` char(3) character set latin2 NOT NULL default '',
`trim(LEADING _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '',
`trim(TRAILING _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '',
`trim(BOTH _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '',
`repeat(_latin2'a',10)` char(10) character set latin2 NOT NULL default '',
`reverse(_latin2'ab')` char(2) character set latin2 NOT NULL default '',
`quote(_latin2'ab')` char(6) character set latin2 NOT NULL default '',
`soundex(_latin2'ab')` char(4) character set latin2 NOT NULL default '',
`substring(_latin2'ab',1)` char(2) character set latin2 NOT NULL default '',
`insert(_latin2'abcd',2,3,_latin2'ef')` char(6) character set latin2 NOT NULL default '',
`replace(_latin2'abcd',_latin2'b',_latin2'B')` char(4) character set latin2 NOT NULL default '',
`encode('abcd','ab')` binary(4) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select SUBSTR('abcdefg',3,2);
SUBSTR('abcdefg',3,2)
cd
select SUBSTRING('abcdefg',3,2);
SUBSTRING('abcdefg',3,2)
cd
select SUBSTR('abcdefg',-3,2) FROM DUAL;
SUBSTR('abcdefg',-3,2)
ef
select SUBSTR('abcdefg',-1,5) FROM DUAL;
SUBSTR('abcdefg',-1,5)
g
select SUBSTR('abcdefg',0,0) FROM DUAL;
SUBSTR('abcdefg',0,0)
select SUBSTR('abcdefg',-1,-1) FROM DUAL;
SUBSTR('abcdefg',-1,-1)
select SUBSTR('abcdefg',1,-1) FROM DUAL;
SUBSTR('abcdefg',1,-1)
create table t7 (s1 char);
select * from t7
where concat(s1 collate latin1_general_ci,s1 collate latin1_swedish_ci) = 'AA';
ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT) and (latin1_swedish_ci,EXPLICIT) for operation 'concat'
drop table t7;
select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2);
substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2)
1abcd;2abcd 3abcd;4abcd
explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"),replace('aaaa','a','b'),insert('txs',2,1,'hi'),left(_latin2'a',1),right(_latin2'a',1),lcase(_latin2'a'),ucase(_latin2'a'),SUBSTR('abcdefg',3,2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),trim(_latin2' a '),ltrim(_latin2' a '),rtrim(_latin2' a '), decode(encode(repeat("a",100000),"monty"),"monty");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,cast(_latin1'HE' as char charset binary) AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate _latin1'latin1_bin'),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")`,replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`,insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`,left(_latin2'a',1) AS `left(_latin2'a',1)`,right(_latin2'a',1) AS `right(_latin2'a',1)`,lcase(_latin2'a') AS `lcase(_latin2'a')`,ucase(_latin2'a') AS `ucase(_latin2'a')`,substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`,substr_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`,trim(_latin2' a ') AS `trim(_latin2' a ')`,ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`,rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`,decode(encode(repeat(_latin1'a',100000))) AS `decode(encode(repeat("a",100000),"monty"),"monty")`
SELECT lpad(12345, 5, "#");
lpad(12345, 5, "#")
12345
SELECT conv(71, 10, 36), conv('1Z', 36, 10);
conv(71, 10, 36) conv('1Z', 36, 10)
1Z 71
create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8;
insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb');
create table t2 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8;
insert into t2 values (1,'cccccccccc'), (2,'dddddddddd');
select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2
where t2.id=t1.id order by name;
name
aaaaaaaaaaccccc
bbbbbbbbbbddddd
drop table t1, t2;
create table t1 (c1 INT, c2 INT UNSIGNED);
insert into t1 values ('21474836461','21474836461');
Warnings:
Warning 1265 Data truncated for column 'c1' at row 1
Warning 1265 Data truncated for column 'c2' at row 1
insert into t1 values ('-21474836461','-21474836461');
Warnings:
Warning 1265 Data truncated for column 'c1' at row 1
Warning 1265 Data truncated for column 'c2' at row 1
show warnings;
Level Code Message
Warning 1265 Data truncated for column 'c1' at row 1
Warning 1265 Data truncated for column 'c2' at row 1
select * from t1; select * from t1;
c1 c2 c1 c2
2147483647 4294967295 2147483647 4294967295
......
...@@ -68,3 +68,11 @@ drop table t1; ...@@ -68,3 +68,11 @@ drop table t1;
select TRUE,FALSE,NULL; select TRUE,FALSE,NULL;
TRUE FALSE NULL TRUE FALSE NULL
1 0 NULL 1 0 NULL
create table t1 (a char(10)) character set latin1;
select * from t1 where a=version();
a
select * from t1 where a=database();
a
select * from t1 where a=user();
a
drop table t1;
...@@ -509,7 +509,7 @@ charset(load_file('../../std_data/words.dat')), ...@@ -509,7 +509,7 @@ charset(load_file('../../std_data/words.dat')),
collation(load_file('../../std_data/words.dat')), collation(load_file('../../std_data/words.dat')),
coercibility(load_file('../../std_data/words.dat')); coercibility(load_file('../../std_data/words.dat'));
charset(load_file('../../std_data/words.dat')) collation(load_file('../../std_data/words.dat')) coercibility(load_file('../../std_data/words.dat')) charset(load_file('../../std_data/words.dat')) collation(load_file('../../std_data/words.dat')) coercibility(load_file('../../std_data/words.dat'))
binary binary 3 binary binary 4
explain extended select explain extended select
charset(load_file('../../std_data/words.dat')), charset(load_file('../../std_data/words.dat')),
collation(load_file('../../std_data/words.dat')), collation(load_file('../../std_data/words.dat')),
......
...@@ -536,4 +536,32 @@ drop table t1, t2, t3; ...@@ -536,4 +536,32 @@ drop table t1, t2, t3;
CREATE TABLE t1 (id int(11),value1 float(10,2)); CREATE TABLE t1 (id int(11),value1 float(10,2));
INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00), (2,13.00); INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00), (2,13.00);
select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id; select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id;
#
# Bug 8893: wrong result for min/max optimization with 2 indexes
#
CREATE TABLE t1(
id int PRIMARY KEY,
a int,
b int,
INDEX i_b_id(a,b,id),
INDEX i_id(a,id)
);
INSERT INTO t1 VALUES
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
DROP TABLE t1;
# change the order of the last two index definitions
CREATE TABLE t1(
id int PRIMARY KEY,
a int,
b int,
INDEX i_id(a,id),
INDEX i_b_id(a,b,id)
);
INSERT INTO t1 VALUES
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
DROP TABLE t1; DROP TABLE t1;
...@@ -30,3 +30,12 @@ show create table t1; ...@@ -30,3 +30,12 @@ show create table t1;
drop table t1; drop table t1;
select TRUE,FALSE,NULL; select TRUE,FALSE,NULL;
#
# Bug#8291 Illegal collation mix with USER() function
#
create table t1 (a char(10)) character set latin1;
select * from t1 where a=version();
select * from t1 where a=database();
select * from t1 where a=user();
drop table t1;
...@@ -2632,6 +2632,7 @@ ha_innobase::write_row( ...@@ -2632,6 +2632,7 @@ ha_innobase::write_row(
table->timestamp_field->set_time(); table->timestamp_field->set_time();
if ((user_thd->lex->sql_command == SQLCOM_ALTER_TABLE if ((user_thd->lex->sql_command == SQLCOM_ALTER_TABLE
|| user_thd->lex->sql_command == SQLCOM_OPTIMIZE
|| user_thd->lex->sql_command == SQLCOM_CREATE_INDEX || user_thd->lex->sql_command == SQLCOM_CREATE_INDEX
|| user_thd->lex->sql_command == SQLCOM_DROP_INDEX) || user_thd->lex->sql_command == SQLCOM_DROP_INDEX)
&& num_write_row >= 10000) { && num_write_row >= 10000) {
......
...@@ -724,7 +724,6 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array, ...@@ -724,7 +724,6 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
*/ */
bool DTCollation::aggregate(DTCollation &dt, uint flags) bool DTCollation::aggregate(DTCollation &dt, uint flags)
{ {
nagg++;
if (!my_charset_same(collation, dt.collation)) if (!my_charset_same(collation, dt.collation))
{ {
/* /*
...@@ -740,7 +739,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ...@@ -740,7 +739,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
else else
{ {
set(dt); set(dt);
strong= nagg;
} }
} }
else if (dt.collation == &my_charset_bin) else if (dt.collation == &my_charset_bin)
...@@ -748,7 +746,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ...@@ -748,7 +746,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
if (dt.derivation <= derivation) if (dt.derivation <= derivation)
{ {
set(dt); set(dt);
strong= nagg;
} }
else else
; // Do nothing ; // Do nothing
...@@ -764,20 +761,18 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ...@@ -764,20 +761,18 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
dt.collation->state & MY_CS_UNICODE) dt.collation->state & MY_CS_UNICODE)
{ {
set(dt); set(dt);
strong= nagg;
} }
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) && else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
derivation < dt.derivation && derivation < dt.derivation &&
dt.derivation >= DERIVATION_COERCIBLE) dt.derivation >= DERIVATION_SYSCONST)
{ {
// Do nothing; // Do nothing;
} }
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) && else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
dt.derivation < derivation && dt.derivation < derivation &&
derivation >= DERIVATION_COERCIBLE) derivation >= DERIVATION_SYSCONST)
{ {
set(dt); set(dt);
strong= nagg;
} }
else else
{ {
...@@ -793,7 +788,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ...@@ -793,7 +788,6 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
else if (dt.derivation < derivation) else if (dt.derivation < derivation)
{ {
set(dt); set(dt);
strong= nagg;
} }
else else
{ {
......
...@@ -32,8 +32,9 @@ class Item_field; ...@@ -32,8 +32,9 @@ class Item_field;
enum Derivation enum Derivation
{ {
DERIVATION_IGNORABLE= 4, DERIVATION_IGNORABLE= 5,
DERIVATION_COERCIBLE= 3, DERIVATION_COERCIBLE= 4,
DERIVATION_SYSCONST= 3,
DERIVATION_IMPLICIT= 2, DERIVATION_IMPLICIT= 2,
DERIVATION_NONE= 1, DERIVATION_NONE= 1,
DERIVATION_EXPLICIT= 0 DERIVATION_EXPLICIT= 0
...@@ -62,22 +63,16 @@ class DTCollation { ...@@ -62,22 +63,16 @@ class DTCollation {
public: public:
CHARSET_INFO *collation; CHARSET_INFO *collation;
enum Derivation derivation; enum Derivation derivation;
uint nagg; // Total number of aggregated collations.
uint strong; // Number of the strongest collation.
DTCollation() DTCollation()
{ {
collation= &my_charset_bin; collation= &my_charset_bin;
derivation= DERIVATION_NONE; derivation= DERIVATION_NONE;
nagg= 0;
strong= 0;
} }
DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg) DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg)
{ {
collation= collation_arg; collation= collation_arg;
derivation= derivation_arg; derivation= derivation_arg;
nagg= 0;
strong= 0;
} }
void set(DTCollation &dt) void set(DTCollation &dt)
{ {
...@@ -103,6 +98,7 @@ public: ...@@ -103,6 +98,7 @@ public:
case DERIVATION_IGNORABLE: return "IGNORABLE"; case DERIVATION_IGNORABLE: return "IGNORABLE";
case DERIVATION_COERCIBLE: return "COERCIBLE"; case DERIVATION_COERCIBLE: return "COERCIBLE";
case DERIVATION_IMPLICIT: return "IMPLICIT"; case DERIVATION_IMPLICIT: return "IMPLICIT";
case DERIVATION_SYSCONST: return "SYSCONST";
case DERIVATION_EXPLICIT: return "EXPLICIT"; case DERIVATION_EXPLICIT: return "EXPLICIT";
case DERIVATION_NONE: return "NONE"; case DERIVATION_NONE: return "NONE";
default: return "UNKNOWN"; default: return "UNKNOWN";
......
...@@ -434,7 +434,7 @@ Item *create_func_version(void) ...@@ -434,7 +434,7 @@ Item *create_func_version(void)
{ {
return new Item_static_string_func("version()", server_version, return new Item_static_string_func("version()", server_version,
(uint) strlen(server_version), (uint) strlen(server_version),
system_charset_info, DERIVATION_IMPLICIT); system_charset_info, DERIVATION_SYSCONST);
} }
Item *create_func_weekday(Item* a) Item *create_func_weekday(Item* a)
......
...@@ -82,8 +82,6 @@ bool Item_func::agg_arg_collations(DTCollation &c, Item **av, uint count, ...@@ -82,8 +82,6 @@ bool Item_func::agg_arg_collations(DTCollation &c, Item **av, uint count,
uint flags) uint flags)
{ {
uint i; uint i;
c.nagg= 0;
c.strong= 0;
c.set(av[0]->collation); c.set(av[0]->collation);
for (i= 1; i < count; i++) for (i= 1; i < count; i++)
{ {
......
...@@ -1515,6 +1515,23 @@ String *Item_func_decode::val_str(String *str) ...@@ -1515,6 +1515,23 @@ String *Item_func_decode::val_str(String *str)
} }
Item *Item_func_sysconst::safe_charset_converter(CHARSET_INFO *tocs)
{
Item_string *conv;
uint conv_errors;
String tmp, cstr, *ostr= val_str(&tmp);
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
cstr.charset(),
collation.derivation)))
{
return NULL;
}
conv->str_value.copy();
return conv;
}
String *Item_func_database::val_str(String *str) String *Item_func_database::val_str(String *str)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
......
...@@ -337,10 +337,18 @@ public: ...@@ -337,10 +337,18 @@ public:
}; };
class Item_func_database :public Item_str_func class Item_func_sysconst :public Item_str_func
{ {
public: public:
Item_func_database() { collation.set(system_charset_info,DERIVATION_IMPLICIT); } Item_func_sysconst()
{ collation.set(system_charset_info,DERIVATION_SYSCONST); }
Item *safe_charset_converter(CHARSET_INFO *tocs);
};
class Item_func_database :public Item_func_sysconst
{
public:
Item_func_database() :Item_func_sysconst() {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() void fix_length_and_dec()
{ {
...@@ -350,10 +358,10 @@ public: ...@@ -350,10 +358,10 @@ public:
const char *func_name() const { return "database"; } const char *func_name() const { return "database"; }
}; };
class Item_func_user :public Item_str_func class Item_func_user :public Item_func_sysconst
{ {
public: public:
Item_func_user() { collation.set(system_charset_info, DERIVATION_IMPLICIT); } Item_func_user() :Item_func_sysconst() {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() void fix_length_and_dec()
{ {
......
...@@ -638,7 +638,6 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, ...@@ -638,7 +638,6 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
{ {
if (!(field->flags & PART_KEY_FLAG)) if (!(field->flags & PART_KEY_FLAG))
return 0; // Not key field return 0; // Not key field
*prefix_len= 0;
TABLE *table= field->table; TABLE *table= field->table;
uint idx= 0; uint idx= 0;
...@@ -651,6 +650,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, ...@@ -651,6 +650,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
KEY_PART_INFO *part,*part_end; KEY_PART_INFO *part,*part_end;
key_part_map key_part_to_use= 0; key_part_map key_part_to_use= 0;
uint jdx= 0; uint jdx= 0;
*prefix_len= 0;
for (part= keyinfo->key_part, part_end= part+keyinfo->key_parts ; for (part= keyinfo->key_part, part_end= part+keyinfo->key_parts ;
part != part_end ; part != part_end ;
part++, jdx++, key_part_to_use= (key_part_to_use << 1) | 1) part++, jdx++, key_part_to_use= (key_part_to_use << 1) | 1)
......
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