@@ -6581,8 +6581,6 @@ static inline bool is_escape_char(char c, char in_string)
6581
6581
6582
6582
SYNOPSIS
6583
6583
read_line
6584
- buf buffer for the read line
6585
- size size of the buffer i.e max size to read
6586
6584
6587
6585
DESCRIPTION
6588
6586
This function actually reads several lines and adds them to the
@@ -6600,21 +6598,37 @@ static inline bool is_escape_char(char c, char in_string)
6600
6598
6601
6599
*/
6602
6600
6603
- int read_line (char *buf, int size)
6601
+ static char *read_command_buf= NULL ;
6602
+ static size_t read_command_buflen= 0 ;
6603
+ static const size_t max_multibyte_length= 6 ;
6604
+
6605
+ int read_line ()
6604
6606
{
6605
6607
char c, last_quote=0 , last_char= 0 ;
6606
- char *p= buf, *buf_end= buf + size - 1 ;
6608
+ char *p= read_command_buf;
6609
+ char *buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
6607
6610
int skip_char= 0 ;
6608
6611
my_bool have_slash= FALSE ;
6609
6612
6610
6613
enum {R_NORMAL, R_Q, R_SLASH_IN_Q,
6611
6614
R_COMMENT, R_LINE_START} state= R_LINE_START;
6612
6615
DBUG_ENTER (" read_line" );
6613
6616
6617
+ *p= 0 ;
6614
6618
start_lineno= cur_file->lineno ;
6615
6619
DBUG_PRINT (" info" , (" Starting to read at lineno: %d" , start_lineno));
6616
- for (; p < buf_end ; )
6620
+ while ( 1 )
6617
6621
{
6622
+ if (p >= buf_end)
6623
+ {
6624
+ my_ptrdiff_t off= p - read_command_buf;
6625
+ read_command_buf= (char *)my_realloc (read_command_buf,
6626
+ read_command_buflen*2 , MYF (MY_FAE));
6627
+ p= read_command_buf + off;
6628
+ read_command_buflen*= 2 ;
6629
+ buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
6630
+ }
6631
+
6618
6632
skip_char= 0 ;
6619
6633
c= my_getc (cur_file->file );
6620
6634
if (feof (cur_file->file ))
@@ -6650,7 +6664,7 @@ int read_line(char *buf, int size)
6650
6664
cur_file->lineno ++;
6651
6665
6652
6666
/* Convert cr/lf to lf */
6653
- if (p != buf && *(p-1 ) == ' \r ' )
6667
+ if (p != read_command_buf && *(p-1 ) == ' \r ' )
6654
6668
p--;
6655
6669
}
6656
6670
@@ -6665,9 +6679,9 @@ int read_line(char *buf, int size)
6665
6679
}
6666
6680
else if ((c == ' {' &&
6667
6681
(!my_strnncoll_simple (charset_info, (const uchar*) " while" , 5 ,
6668
- (uchar*) buf , MY_MIN (5 , p - buf ), 0 ) ||
6682
+ (uchar*) read_command_buf , MY_MIN (5 , p - read_command_buf ), 0 ) ||
6669
6683
!my_strnncoll_simple (charset_info, (const uchar*) " if" , 2 ,
6670
- (uchar*) buf , MY_MIN (2 , p - buf ), 0 ))))
6684
+ (uchar*) read_command_buf , MY_MIN (2 , p - read_command_buf ), 0 ))))
6671
6685
{
6672
6686
/* Only if and while commands can be terminated by { */
6673
6687
*p++= c;
@@ -6799,8 +6813,6 @@ int read_line(char *buf, int size)
6799
6813
}
6800
6814
}
6801
6815
}
6802
- die (" The input buffer is too small for this query.\n "
6803
- " check your query or increase MAX_QUERY and recompile" );
6804
6816
DBUG_RETURN (0 );
6805
6817
}
6806
6818
@@ -6945,12 +6957,8 @@ bool is_delimiter(const char* p)
6945
6957
terminated by new line '\n' regardless how many "delimiter" it contain.
6946
6958
*/
6947
6959
6948
- #define MAX_QUERY (256 *1024 *2 ) /* 256K -- a test in sp-big is >128K */
6949
- static char read_command_buf[MAX_QUERY];
6950
-
6951
6960
int read_command (struct st_command ** command_ptr)
6952
6961
{
6953
- char *p= read_command_buf;
6954
6962
struct st_command * command;
6955
6963
DBUG_ENTER (" read_command" );
6956
6964
@@ -6967,8 +6975,7 @@ int read_command(struct st_command** command_ptr)
6967
6975
die (" Out of memory" );
6968
6976
command->type = Q_UNKNOWN;
6969
6977
6970
- read_command_buf[0 ]= 0 ;
6971
- if (read_line (read_command_buf, sizeof (read_command_buf)))
6978
+ if (read_line ())
6972
6979
{
6973
6980
check_eol_junk (read_command_buf);
6974
6981
DBUG_RETURN (1 );
@@ -6977,6 +6984,7 @@ int read_command(struct st_command** command_ptr)
6977
6984
if (opt_result_format_version == 1 )
6978
6985
convert_to_format_v1 (read_command_buf);
6979
6986
6987
+ char *p= read_command_buf;
6980
6988
DBUG_PRINT (" info" , (" query: '%s'" , read_command_buf));
6981
6989
if (*p == ' #' )
6982
6990
{
@@ -9204,6 +9212,8 @@ int main(int argc, char **argv)
9204
9212
init_win_path_patterns ();
9205
9213
#endif
9206
9214
9215
+ read_command_buf= (char *)my_malloc (read_command_buflen= 65536 , MYF (MY_FAE));
9216
+
9207
9217
init_dynamic_string (&ds_res, " " , 2048 , 2048 );
9208
9218
init_alloc_root (&require_file_root, " require_file" , 1024 , 1024 , MYF (0 ));
9209
9219
0 commit comments