Skip to content

Commit 410e51c

Browse files
Fixed failing test cases 'row.test' when running with --ps-protocol
Simple optimzations done while reviewing code
1 parent 919f2f2 commit 410e51c

9 files changed

Lines changed: 116 additions & 116 deletions

File tree

client/mysqltest.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ VAR var_reg[10];
253253
/*Perl/shell-like variable registers */
254254
HASH var_hash;
255255
my_bool disable_query_log=0, disable_result_log=0, disable_warnings=0;
256+
my_bool disable_ps_warnings= 0;
256257
my_bool disable_info= 1; /* By default off */
257258
my_bool abort_on_error= 1;
258259

@@ -283,6 +284,7 @@ Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
283284
Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER,
284285
Q_WAIT_FOR_SLAVE_TO_STOP,
285286
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
287+
Q_ENABLE_PS_WARNINGS, Q_DISABLE_PS_WARNINGS,
286288
Q_ENABLE_INFO, Q_DISABLE_INFO,
287289
Q_ENABLE_METADATA, Q_DISABLE_METADATA,
288290
Q_EXEC, Q_DELIMITER,
@@ -360,6 +362,8 @@ const char *command_names[]=
360362
"wait_for_slave_to_stop",
361363
"enable_warnings",
362364
"disable_warnings",
365+
"enable_ps_warnings",
366+
"disable_ps_warnings",
363367
"enable_info",
364368
"disable_info",
365369
"enable_metadata",
@@ -3021,7 +3025,8 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
30213025

30223026
/* We may have got warnings already, collect them if any */
30233027
/* FIXME we only want this if the statement succeeds I think */
3024-
run_query_stmt_handle_warnings(mysql, ds);
3028+
if (!disable_ps_warnings)
3029+
run_query_stmt_handle_warnings(mysql, ds);
30253030

30263031
/*
30273032
No need to call mysql_stmt_bind_param() because we have no
@@ -3711,6 +3716,8 @@ int main(int argc, char **argv)
37113716
case Q_DISABLE_RESULT_LOG: disable_result_log=1; break;
37123717
case Q_ENABLE_WARNINGS: disable_warnings=0; break;
37133718
case Q_DISABLE_WARNINGS: disable_warnings=1; break;
3719+
case Q_ENABLE_PS_WARNINGS: disable_ps_warnings=0; break;
3720+
case Q_DISABLE_PS_WARNINGS: disable_ps_warnings=1; break;
37143721
case Q_ENABLE_INFO: disable_info=0; break;
37153722
case Q_DISABLE_INFO: disable_info=1; break;
37163723
case Q_ENABLE_METADATA: display_metadata=1; break;

mysql-test/t/row.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ select (1,2,3) IN ((3,2,3), (1,2,3), (1,3,3));
77
select row(10,2,3) IN (row(3,2,3), row(1,2,3), row(1,3,3));
88
select row(1,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
99
select row(10,2,3) IN (row(3,NULL,3), row(1,2,3), row(1,3,3));
10+
--disable_ps_warnings
1011
select row('a',1.5,3) IN (row(1,2,3), row('a',1.5,3), row('a','a','a'));
12+
--enable_ps_warnings
1113
select row('a',0,3) IN (row(3,2,3), row('a','0','3'), row(1,3,3));
1214
select row('a',0,3) IN (row(3,2,3), row('a','a','3'), row(1,3,3));
1315
select row('a',1.5,3) IN (row(3,NULL,3), row('a',1.5,3), row(1,3,3));

sql/field.cc

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,7 @@ my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
572572
{
573573
DBUG_ASSERT(result_type() == INT_RESULT);
574574
longlong nr= val_int();
575-
if (!is_null())
576-
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
575+
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
577576
return decimal_value;
578577
}
579578

@@ -605,7 +604,7 @@ void Field_num::make_field(Send_field *field)
605604
d value for storing
606605
607606
NOTE
608-
Field_str is the base class for fields like Field_date, and some
607+
Field_str is the base class for fields like Field_enum, Field_date and some
609608
similar. Some dates use fraction and also string value should be
610609
converted to floating point value according our rules, so we use double
611610
to store value of decimal in string
@@ -629,8 +628,7 @@ my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
629628
{
630629
DBUG_ASSERT(result_type() == INT_RESULT);
631630
longlong nr= val_int();
632-
if (is_null())
633-
int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
631+
int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
634632
return decimal_value;
635633
}
636634

@@ -733,6 +731,7 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
733731
return tmp;
734732
}
735733

734+
736735
/*
737736
SYNOPSIS
738737
Field::quote_data()
@@ -749,44 +748,35 @@ Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
749748
void Upon prepending/appending quotes on each side of variable
750749
751750
*/
751+
752752
bool Field::quote_data(String *unquoted_string)
753753
{
754754
char escaped_string[IO_SIZE];
755755
char *unquoted_string_buffer= (char *)(unquoted_string->ptr());
756756
uint need_quotes;
757-
758757
DBUG_ENTER("Field::quote_data");
758+
759759
// this is the same call that mysql_real_escape_string() calls
760760
escape_string_for_mysql(&my_charset_bin, (char *)escaped_string,
761761
unquoted_string->ptr(), unquoted_string->length());
762762

763-
764-
if (is_null())
765-
DBUG_RETURN(0);
766-
767763
need_quotes= needs_quotes();
768764

769765
if (need_quotes == 0)
770-
{
771766
DBUG_RETURN(0);
772-
}
773-
else
774-
{
775-
// reset string, then re-append with quotes and escaped values
776-
unquoted_string->length(0);
777-
if (unquoted_string->append("'"))
778-
DBUG_RETURN(1);
779-
if (unquoted_string->append((char *)escaped_string))
780-
DBUG_RETURN(1);
781-
if (unquoted_string->append("'"))
782-
DBUG_RETURN(1);
783-
}
784-
//DBUG_PRINT("Field::quote_data",
785-
// ("FINAL quote_flag %d unquoted_string %s escaped_string %s",
786-
//needs_quotes, unquoted_string->c_ptr_quick(), escaped_string));
767+
768+
// reset string, then re-append with quotes and escaped values
769+
unquoted_string->length(0);
770+
if (unquoted_string->append('\''))
771+
DBUG_RETURN(1);
772+
if (unquoted_string->append((char *)escaped_string))
773+
DBUG_RETURN(1);
774+
if (unquoted_string->append('\''))
775+
DBUG_RETURN(1);
787776
DBUG_RETURN(0);
788777
}
789778

779+
790780
/*
791781
Quote a field type if needed
792782
@@ -802,6 +792,7 @@ bool Field::quote_data(String *unquoted_string)
802792
0 if value is of type NOT needing quotes
803793
1 if value is of type needing quotes
804794
*/
795+
805796
bool Field::needs_quotes(void)
806797
{
807798
DBUG_ENTER("Field::type_quote");
@@ -840,9 +831,9 @@ bool Field::needs_quotes(void)
840831
default: DBUG_RETURN(0);
841832
}
842833
DBUG_RETURN(0);
843-
844834
}
845835

836+
846837
/****************************************************************************
847838
Field_null, a field that always return NULL
848839
****************************************************************************/
@@ -4646,8 +4637,6 @@ String *Field_newdate::val_str(String *val_buffer,
46464637

46474638
bool Field_newdate::get_date(TIME *ltime,uint fuzzydate)
46484639
{
4649-
if (is_null())
4650-
return 1;
46514640
uint32 tmp=(uint32) uint3korr(ptr);
46524641
ltime->day= tmp & 31;
46534642
ltime->month= (tmp >> 5) & 15;
@@ -5058,17 +5047,16 @@ int Field_string::store(longlong nr)
50585047
return Field_string::store(buff,(uint)l,cs);
50595048
}
50605049

5050+
50615051
int Field_longstr::store_decimal(const my_decimal *d)
50625052
{
5063-
uint buf_size= my_decimal_string_length(d);
5064-
char *buff= (char *)my_alloca(buf_size);
5065-
String str(buff, buf_size, &my_charset_bin);
5053+
char buff[DECIMAL_MAX_STR_LENGTH+1];
5054+
String str(buff, sizeof(buff), &my_charset_bin);
50665055
my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
5067-
int result= store(str.ptr(), str.length(), str.charset());
5068-
my_afree(buff);
5069-
return result;
5056+
return store(str.ptr(), str.length(), str.charset());
50705057
}
50715058

5059+
50725060
double Field_string::val_real(void)
50735061
{
50745062
int not_used;

sql/field.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ class Field_str :public Field {
367367
my_decimal *val_decimal(my_decimal *);
368368
};
369369

370-
/* base class for Item_string, Item_valstring, Item_blob */
370+
371+
/* base class for Field_string, Field_varstring and Field_blob */
372+
371373
class Field_longstr :public Field_str
372374
{
373375
public:
@@ -1181,7 +1183,9 @@ class Field_blob :public Field_longstr {
11811183
bool has_charset(void) const
11821184
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
11831185
field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; }
1184-
uint32 max_length();};
1186+
uint32 max_length();
1187+
};
1188+
11851189

11861190
#ifdef HAVE_SPATIAL
11871191
class Field_geom :public Field_blob {

sql/filesort.cc

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -619,20 +619,21 @@ static void make_sortkey(register SORTPARAM *param,
619619
else
620620
{ // Item
621621
Item *item=sort_field->item;
622+
maybe_null= item->maybe_null;
622623
switch (sort_field->result_type) {
623624
case STRING_RESULT:
624625
{
625626
CHARSET_INFO *cs=item->collation.collation;
626627
char fill_char= ((cs->state & MY_CS_BINSORT) ? (char) 0 : ' ');
627628

628-
if ((maybe_null=item->maybe_null))
629+
if (maybe_null)
629630
*to++=1;
630631
/* All item->str() to use some extra byte for end null.. */
631632
String tmp((char*) to,sort_field->length+4,cs);
632633
String *res=item->val_str(&tmp);
633634
if (!res)
634635
{
635-
if (item->maybe_null)
636+
if (maybe_null)
636637
bzero((char*) to-1,sort_field->length+1);
637638
else
638639
{
@@ -672,20 +673,22 @@ static void make_sortkey(register SORTPARAM *param,
672673
case INT_RESULT:
673674
{
674675
longlong value=item->val_int();
675-
if ((maybe_null=item->maybe_null))
676+
if (maybe_null)
677+
{
676678
*to++=1; /* purecov: inspected */
677-
if (item->null_value)
678-
{
679-
if (item->maybe_null)
680-
bzero((char*) to-1,sort_field->length+1);
681-
else
682-
{
683-
DBUG_PRINT("warning",
684-
("Got null on something that shouldn't be null"));
685-
bzero((char*) to,sort_field->length);
686-
}
687-
break;
688-
}
679+
if (item->null_value)
680+
{
681+
if (maybe_null)
682+
bzero((char*) to-1,sort_field->length+1);
683+
else
684+
{
685+
DBUG_PRINT("warning",
686+
("Got null on something that shouldn't be null"));
687+
bzero((char*) to,sort_field->length);
688+
}
689+
break;
690+
}
691+
}
689692
#if SIZEOF_LONG_LONG > 4
690693
to[7]= (uchar) value;
691694
to[6]= (uchar) (value >> 8);
@@ -706,14 +709,16 @@ static void make_sortkey(register SORTPARAM *param,
706709
case DECIMAL_RESULT:
707710
{
708711
my_decimal dec_buf, *dec_val= item->val_decimal(&dec_buf);
709-
if ((maybe_null=item->null_value))
710-
{
711-
bzero((char*)to, sort_field->length+1);
712-
to++;
713-
break;
714-
}
715-
if ((maybe_null=item->maybe_null))
712+
if (maybe_null)
713+
{
714+
if (item->null_value)
715+
{
716+
bzero((char*)to, sort_field->length+1);
717+
to++;
718+
break;
719+
}
716720
*to++=1;
721+
}
717722
my_decimal2binary(E_DEC_FATAL_ERROR, dec_val, (byte*)to,
718723
item->max_length - (item->decimals ? 1:0),
719724
item->decimals);
@@ -722,14 +727,16 @@ static void make_sortkey(register SORTPARAM *param,
722727
case REAL_RESULT:
723728
{
724729
double value= item->val_real();
725-
if ((maybe_null=item->null_value))
726-
{
727-
bzero((char*) to,sort_field->length+1);
728-
to++;
729-
break;
730-
}
731-
if ((maybe_null=item->maybe_null))
730+
if (maybe_null)
731+
{
732+
if (item->null_value)
733+
{
734+
bzero((char*) to,sort_field->length+1);
735+
to++;
736+
break;
737+
}
732738
*to++=1;
739+
}
733740
change_double_for_sort(value,(byte*) to);
734741
break;
735742
}

0 commit comments

Comments
 (0)