MDEV-9077 - sys schema preparation
- increase MAX_BOOTSTRAP_QUERY_SIZE (sys.schema has SP over 50K large) don't allocate bootstrap query on heap anymore. - support DELIMITER in bootstrap
This commit is contained in:
parent
601c577142
commit
9186ff88da
@ -30,7 +30,7 @@ ENDMACRO()
|
|||||||
|
|
||||||
IF(NOT CMAKE_CROSSCOMPILING)
|
IF(NOT CMAKE_CROSSCOMPILING)
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
|
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
|
||||||
ADD_EXECUTABLE(comp_sql comp_sql.c)
|
ADD_EXECUTABLE(comp_sql comp_sql.c ../sql/sql_bootstrap.cc)
|
||||||
TARGET_LINK_LIBRARIES(comp_sql)
|
TARGET_LINK_LIBRARIES(comp_sql)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
- do not duplicate the code either.
|
- do not duplicate the code either.
|
||||||
so just add the sql_bootstrap.cc code as is.
|
so just add the sql_bootstrap.cc code as is.
|
||||||
*/
|
*/
|
||||||
#include "../sql/sql_bootstrap.cc"
|
#include "../sql/sql_bootstrap.h"
|
||||||
|
|
||||||
FILE *in, *out;
|
FILE *in, *out;
|
||||||
|
|
||||||
@ -121,9 +121,10 @@ static void print_query(FILE *out, const char *query)
|
|||||||
fprintf(out, "\\n\",\n");
|
fprintf(out, "\\n\",\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char query[MAX_BOOTSTRAP_QUERY_SIZE];
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char query[MAX_BOOTSTRAP_QUERY_SIZE];
|
|
||||||
char* struct_name= argv[1];
|
char* struct_name= argv[1];
|
||||||
char* infile_name= argv[2];
|
char* infile_name= argv[2];
|
||||||
char* outfile_name= argv[3];
|
char* outfile_name= argv[3];
|
||||||
@ -151,7 +152,7 @@ int main(int argc, char *argv[])
|
|||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
rc= read_bootstrap_query(query, &query_length,
|
rc= read_bootstrap_query(query, &query_length,
|
||||||
(fgets_input_t) in, fgets_fn, &error);
|
(fgets_input_t) in, fgets_fn, 1, &error);
|
||||||
|
|
||||||
if (rc == READ_BOOTSTRAP_EOF)
|
if (rc == READ_BOOTSTRAP_EOF)
|
||||||
break;
|
break;
|
||||||
|
@ -18,9 +18,20 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sql_bootstrap.h"
|
#include "sql_bootstrap.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
int read_bootstrap_query(char *query, int *query_length,
|
static bool is_end_of_query(const char *line, size_t len,
|
||||||
fgets_input_t input, fgets_fn_t fgets_fn, int *error)
|
const std::string& delimiter)
|
||||||
|
{
|
||||||
|
if (delimiter.length() > len)
|
||||||
|
return false;
|
||||||
|
return !strcmp(line + len-delimiter.length(),delimiter.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string delimiter= ";";
|
||||||
|
extern "C" int read_bootstrap_query(char *query, int *query_length,
|
||||||
|
fgets_input_t input, fgets_fn_t fgets_fn,
|
||||||
|
int preserve_delimiter, int *error)
|
||||||
{
|
{
|
||||||
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
|
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
|
||||||
const char *line;
|
const char *line;
|
||||||
@ -73,10 +84,33 @@ int read_bootstrap_query(char *query, int *query_length,
|
|||||||
if ((line[0] == '-') && (line[1] == '-'))
|
if ((line[0] == '-') && (line[1] == '-'))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Skip delimiter, ignored. */
|
size_t i=0;
|
||||||
if (strncmp(line, "delimiter", 9) == 0)
|
while (line[i] == ' ')
|
||||||
|
i++;
|
||||||
|
|
||||||
|
/* Skip -- comments */
|
||||||
|
if (line[i] == '-' && line[i+1] == '-')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (strncmp(line, "DELIMITER", 9) == 0)
|
||||||
|
{
|
||||||
|
const char *p= strrchr(line,' ');
|
||||||
|
if (!p || !p[1])
|
||||||
|
{
|
||||||
|
/* Invalid DELIMITER specifier */
|
||||||
|
return READ_BOOTSTRAP_ERROR;
|
||||||
|
}
|
||||||
|
delimiter.assign(p+1);
|
||||||
|
if (preserve_delimiter)
|
||||||
|
{
|
||||||
|
memcpy(query,line,len);
|
||||||
|
query[len]=0;
|
||||||
|
*query_length = (int)len;
|
||||||
|
return READ_BOOTSTRAP_SUCCESS;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Append the current line to a multi line query. If the new line will make
|
/* Append the current line to a multi line query. If the new line will make
|
||||||
the query too long, preserve the partial line to provide context for the
|
the query too long, preserve the partial line to provide context for the
|
||||||
error message.
|
error message.
|
||||||
@ -105,13 +139,18 @@ int read_bootstrap_query(char *query, int *query_length,
|
|||||||
memcpy(query + query_len, line, len);
|
memcpy(query + query_len, line, len);
|
||||||
query_len+= len;
|
query_len+= len;
|
||||||
|
|
||||||
if (line[len - 1] == ';')
|
if (is_end_of_query(line, len, delimiter))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The last line is terminated by ';'.
|
The last line is terminated by delimiter
|
||||||
Return the query found.
|
Return the query found.
|
||||||
*/
|
*/
|
||||||
query[query_len]= '\0';
|
if (!preserve_delimiter)
|
||||||
|
{
|
||||||
|
query_len-= delimiter.length();
|
||||||
|
query[query_len++]= ';';
|
||||||
|
}
|
||||||
|
query[query_len]= 0;
|
||||||
*query_length= (int)query_len;
|
*query_length= (int)query_len;
|
||||||
return READ_BOOTSTRAP_SUCCESS;
|
return READ_BOOTSTRAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
The longest query in use depends on the documentation content,
|
The longest query in use depends on the documentation content,
|
||||||
see the file fill_help_tables.sql
|
see the file fill_help_tables.sql
|
||||||
*/
|
*/
|
||||||
#define MAX_BOOTSTRAP_QUERY_SIZE 20000
|
#define MAX_BOOTSTRAP_QUERY_SIZE 60000
|
||||||
/**
|
/**
|
||||||
The maximum size of a bootstrap query, expressed in a single line.
|
The maximum size of a bootstrap query, expressed in a single line.
|
||||||
Do not increase this size, use the multiline syntax instead.
|
Do not increase this size, use the multiline syntax instead.
|
||||||
@ -39,8 +39,16 @@
|
|||||||
typedef void *fgets_input_t;
|
typedef void *fgets_input_t;
|
||||||
typedef char * (*fgets_fn_t)(char *, size_t, fgets_input_t, int *error);
|
typedef char * (*fgets_fn_t)(char *, size_t, fgets_input_t, int *error);
|
||||||
|
|
||||||
int read_bootstrap_query(char *query, int *query_length,
|
#ifdef __cplusplus
|
||||||
fgets_input_t input, fgets_fn_t fgets_fn, int *error);
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
int read_bootstrap_query(char *query, int *query_length, fgets_input_t input,
|
||||||
|
fgets_fn_t fgets_fn,
|
||||||
|
int preserve_delimiter,
|
||||||
|
int *error);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -978,6 +978,7 @@ int bootstrap(MYSQL_FILE *file)
|
|||||||
DBUG_ENTER("handle_bootstrap");
|
DBUG_ENTER("handle_bootstrap");
|
||||||
|
|
||||||
THD *thd= new THD(next_thread_id());
|
THD *thd= new THD(next_thread_id());
|
||||||
|
char *buffer= new char[MAX_BOOTSTRAP_QUERY_SIZE];
|
||||||
#ifdef WITH_WSREP
|
#ifdef WITH_WSREP
|
||||||
thd->variables.wsrep_on= 0;
|
thd->variables.wsrep_on= 0;
|
||||||
#endif
|
#endif
|
||||||
@ -1011,12 +1012,12 @@ int bootstrap(MYSQL_FILE *file)
|
|||||||
|
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
char buffer[MAX_BOOTSTRAP_QUERY_SIZE] = "";
|
buffer[0]= 0;
|
||||||
int rc, length;
|
int rc, length;
|
||||||
char *query;
|
char *query;
|
||||||
int error= 0;
|
int error= 0;
|
||||||
|
|
||||||
rc= read_bootstrap_query(buffer, &length, file, fgets_fn, &error);
|
rc= read_bootstrap_query(buffer, &length, file, fgets_fn, 0, &error);
|
||||||
|
|
||||||
if (rc == READ_BOOTSTRAP_EOF)
|
if (rc == READ_BOOTSTRAP_EOF)
|
||||||
break;
|
break;
|
||||||
@ -1099,6 +1100,7 @@ int bootstrap(MYSQL_FILE *file)
|
|||||||
thd->lex->restore_set_statement_var();
|
thd->lex->restore_set_statement_var();
|
||||||
}
|
}
|
||||||
delete thd;
|
delete thd;
|
||||||
|
delete[] buffer;
|
||||||
DBUG_RETURN(bootstrap_error);
|
DBUG_RETURN(bootstrap_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user