@@ -6501,8 +6501,6 @@ static inline bool is_escape_char(char c, char in_string)
6501
6501
6502
6502
SYNOPSIS
6503
6503
read_line
6504
- buf buffer for the read line
6505
- size size of the buffer i.e max size to read
6506
6504
6507
6505
DESCRIPTION
6508
6506
This function actually reads several lines and adds them to the
@@ -6520,21 +6518,37 @@ static inline bool is_escape_char(char c, char in_string)
6520
6518
6521
6519
*/
6522
6520
6523
- int read_line (char *buf, int size)
6521
+ static char *read_command_buf= NULL ;
6522
+ static size_t read_command_buflen= 0 ;
6523
+ static const size_t max_multibyte_length= 6 ;
6524
+
6525
+ int read_line ()
6524
6526
{
6525
6527
char c, last_quote=0 , last_char= 0 ;
6526
- char *p= buf, *buf_end= buf + size - 1 ;
6528
+ char *p= read_command_buf;
6529
+ char *buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
6527
6530
int skip_char= 0 ;
6528
6531
my_bool have_slash= FALSE ;
6529
6532
6530
6533
enum {R_NORMAL, R_Q, R_SLASH_IN_Q,
6531
6534
R_COMMENT, R_LINE_START} state= R_LINE_START;
6532
6535
DBUG_ENTER (" read_line" );
6533
6536
6537
+ *p= 0 ;
6534
6538
start_lineno= cur_file->lineno ;
6535
6539
DBUG_PRINT (" info" , (" Starting to read at lineno: %d" , start_lineno));
6536
- for (; p < buf_end ; )
6540
+ while ( 1 )
6537
6541
{
6542
+ if (p >= buf_end)
6543
+ {
6544
+ my_ptrdiff_t off= p - read_command_buf;
6545
+ read_command_buf= (char *)my_realloc (read_command_buf,
6546
+ read_command_buflen*2 , MYF (MY_FAE));
6547
+ p= read_command_buf + off;
6548
+ read_command_buflen*= 2 ;
6549
+ buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
6550
+ }
6551
+
6538
6552
skip_char= 0 ;
6539
6553
c= my_getc (cur_file->file );
6540
6554
if (feof (cur_file->file ))
@@ -6570,7 +6584,7 @@ int read_line(char *buf, int size)
6570
6584
cur_file->lineno ++;
6571
6585
6572
6586
/* Convert cr/lf to lf */
6573
- if (p != buf && *(p-1 ) == ' \r ' )
6587
+ if (p != read_command_buf && *(p-1 ) == ' \r ' )
6574
6588
p--;
6575
6589
}
6576
6590
@@ -6585,9 +6599,9 @@ int read_line(char *buf, int size)
6585
6599
}
6586
6600
else if ((c == ' {' &&
6587
6601
(!my_strnncoll_simple (charset_info, (const uchar*) " while" , 5 ,
6588
- (uchar*) buf , min (5 , p - buf ), 0 ) ||
6602
+ (uchar*) read_command_buf , min (5 , p - read_command_buf ), 0 ) ||
6589
6603
!my_strnncoll_simple (charset_info, (const uchar*) " if" , 2 ,
6590
- (uchar*) buf , min (2 , p - buf ), 0 ))))
6604
+ (uchar*) read_command_buf , min (2 , p - read_command_buf ), 0 ))))
6591
6605
{
6592
6606
/* Only if and while commands can be terminated by { */
6593
6607
*p++= c;
@@ -6721,8 +6735,6 @@ int read_line(char *buf, int size)
6721
6735
*p++= c;
6722
6736
}
6723
6737
}
6724
- die (" The input buffer is too small for this query.x\n " \
6725
- " check your query or increase MAX_QUERY and recompile" );
6726
6738
DBUG_RETURN (0 );
6727
6739
}
6728
6740
@@ -6867,12 +6879,8 @@ bool is_delimiter(const char* p)
6867
6879
terminated by new line '\n' regardless how many "delimiter" it contain.
6868
6880
*/
6869
6881
6870
- #define MAX_QUERY (256 *1024 *2 ) /* 256K -- a test in sp-big is >128K */
6871
- static char read_command_buf[MAX_QUERY];
6872
-
6873
6882
int read_command (struct st_command ** command_ptr)
6874
6883
{
6875
- char *p= read_command_buf;
6876
6884
struct st_command * command;
6877
6885
DBUG_ENTER (" read_command" );
6878
6886
@@ -6888,8 +6896,7 @@ int read_command(struct st_command** command_ptr)
6888
6896
die (" Out of memory" );
6889
6897
command->type = Q_UNKNOWN;
6890
6898
6891
- read_command_buf[0 ]= 0 ;
6892
- if (read_line (read_command_buf, sizeof (read_command_buf)))
6899
+ if (read_line ())
6893
6900
{
6894
6901
check_eol_junk (read_command_buf);
6895
6902
DBUG_RETURN (1 );
@@ -6898,6 +6905,7 @@ int read_command(struct st_command** command_ptr)
6898
6905
if (opt_result_format_version == 1 )
6899
6906
convert_to_format_v1 (read_command_buf);
6900
6907
6908
+ char *p= read_command_buf;
6901
6909
DBUG_PRINT (" info" , (" query: '%s'" , read_command_buf));
6902
6910
if (*p == ' #' )
6903
6911
{
@@ -9025,6 +9033,8 @@ int main(int argc, char **argv)
9025
9033
init_win_path_patterns ();
9026
9034
#endif
9027
9035
9036
+ read_command_buf= (char *)my_malloc (read_command_buflen= 65536 , MYF (MY_FAE));
9037
+
9028
9038
init_dynamic_string (&ds_res, " " , 2048 , 2048 );
9029
9039
init_alloc_root (&require_file_root, 1024 , 1024 );
9030
9040
0 commit comments