Commit 55b27888 authored by Monty's avatar Monty

Fixed length estimate for REPLACE()

parent 657fcdf4
...@@ -211,6 +211,11 @@ this is test ...@@ -211,6 +211,11 @@ this is test
select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c'); select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c');
replace('aaaa','a','b') replace('aaaa','aa','b') replace('aaaa','a','bb') replace('aaaa','','b') replace('bbbb','a','c') replace('aaaa','a','b') replace('aaaa','aa','b') replace('aaaa','a','bb') replace('aaaa','','b') replace('bbbb','a','c')
bbbb bb bbbbbbbb aaaa bbbb bbbb bb bbbbbbbb aaaa bbbb
select replace('aaaa','a','bbbb');
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def replace('aaaa','a','bbbb') 253 16 16 Y 0 39 8
replace('aaaa','a','bbbb')
bbbbbbbbbbbbbbbb
select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ; select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL')
this is a REAL test this is a REAL test
......
...@@ -91,6 +91,9 @@ SELECT CONCAT('"',CONCAT_WS('";"',repeat('a',60),repeat('b',60),repeat('c',60),r ...@@ -91,6 +91,9 @@ SELECT CONCAT('"',CONCAT_WS('";"',repeat('a',60),repeat('b',60),repeat('c',60),r
select insert('txs',2,1,'hi'),insert('is ',4,0,'a'),insert('txxxxt',2,4,'es'); select insert('txs',2,1,'hi'),insert('is ',4,0,'a'),insert('txxxxt',2,4,'es');
select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c'); select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c');
--enable_metadata
select replace('aaaa','a','bbbb');
--disable_metadata
select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ; select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
select soundex(''),soundex('he'),soundex('hello all folks'),soundex('#3556 in bugdb'); select soundex(''),soundex('he'),soundex('hello all folks'),soundex('#3556 in bugdb');
select 'mood' sounds like 'mud'; select 'mood' sounds like 'mud';
......
...@@ -267,7 +267,7 @@ t1 CREATE TABLE `t1` ( ...@@ -267,7 +267,7 @@ t1 CREATE TABLE `t1` (
`c30` varchar(317) CHARACTER SET latin2 DEFAULT NULL, `c30` varchar(317) CHARACTER SET latin2 DEFAULT NULL,
`c31` varchar(192) CHARACTER SET latin2 DEFAULT NULL, `c31` varchar(192) CHARACTER SET latin2 DEFAULT NULL,
`c32` char(0) CHARACTER SET latin2 DEFAULT NULL, `c32` char(0) CHARACTER SET latin2 DEFAULT NULL,
`c33` varchar(3) CHARACTER SET latin2 DEFAULT NULL, `c33` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
`c34` varchar(3) CHARACTER SET latin2 DEFAULT NULL, `c34` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
`c35` varchar(3) CHARACTER SET latin2 DEFAULT NULL, `c35` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
`c36` varchar(3) CHARACTER SET latin2 DEFAULT NULL, `c36` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
......
...@@ -1286,10 +1286,10 @@ String *Item_func_replace::val_str_internal(String *str, ...@@ -1286,10 +1286,10 @@ String *Item_func_replace::val_str_internal(String *str,
bool Item_func_replace::fix_length_and_dec() bool Item_func_replace::fix_length_and_dec()
{ {
ulonglong char_length= (ulonglong) args[0]->max_char_length(); ulonglong char_length= (ulonglong) args[0]->max_char_length();
int diff=(int) (args[2]->max_char_length() - args[1]->max_char_length()); int diff=(int) (args[2]->max_char_length() - 1);
if (diff > 0 && args[1]->max_char_length()) if (diff > 0)
{ // Calculate of maxreplaces { // Calculate of maxreplaces
ulonglong max_substrs= char_length / args[1]->max_char_length(); ulonglong max_substrs= char_length;
char_length+= max_substrs * (uint) diff; char_length+= max_substrs * (uint) diff;
} }
......
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