66
66
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
67
67
static bool parse_sql(Session *session, Lex_input_stream *lip);
68
void mysql_parse(Session *session, const char *inBuf, uint32_t length,
69
const char ** found_semicolon);
68
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
72
71
@defgroup Runtime_Environment Runtime Environment
213
212
if (! session->readAndStoreQuery(packet, packet_length))
214
213
break; // fatal error is set
215
DRIZZLE_QUERY_START(session->query,
214
DRIZZLE_QUERY_START(session->query.c_str(),
216
215
session->thread_id,
217
216
const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
218
const char* end_of_stmt= NULL;
220
mysql_parse(session, session->query, session->query_length, &end_of_stmt);
218
mysql_parse(session, session->query.c_str(), session->query.length());
463
460
/* list of all tables in query */
464
461
TableList *all_tables;
465
462
/* A peek into the query string */
466
size_t proc_info_len= session->query_length > PROCESS_LIST_WIDTH ?
467
PROCESS_LIST_WIDTH : session->query_length;
463
size_t proc_info_len= session->query.length() > PROCESS_LIST_WIDTH ?
464
PROCESS_LIST_WIDTH : session->query.length();
469
memcpy(session->process_list_info, session->query, proc_info_len);
466
memcpy(session->process_list_info, session->query.c_str(), proc_info_len);
470
467
session->process_list_info[proc_info_len]= '\0';
742
739
@param session Current thread
743
740
@param inBuf Begining of the query text
744
741
@param length Length of the query text
745
@param[out] found_semicolon For multi queries, position of the character of
746
the next query in the query text.
749
void mysql_parse(Session *session, const char *inBuf, uint32_t length,
750
const char ** found_semicolon)
744
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
754
The purpose of query_cache_send_result_to_client() is to lookup the
755
query in the query cache first, to avoid parsing and executing it.
756
So, the natural implementation would be to:
757
- first, call query_cache_send_result_to_client,
758
- second, if caching failed, initialise the lexical and syntactic parser.
759
The problem is that the query cache depends on a clean initialization
760
of (among others) lex->safe_to_cache_query and session->server_status,
761
which are reset respectively in
763
- mysql_reset_session_for_next_command()
764
So, initializing the lexical analyser *before* using the query cache
765
is required for the cache to work properly.
766
FIXME: cleanup the dependencies in the code to simplify this.
768
746
lex_start(session);
769
747
session->reset_for_next_command();
749
LEX *lex= session->lex;
751
Lex_input_stream lip(session, inBuf, length);
753
bool err= parse_sql(session, &lip);
772
LEX *lex= session->lex;
774
Lex_input_stream lip(session, inBuf, length);
776
bool err= parse_sql(session, &lip);
777
*found_semicolon= lip.found_semicolon;
758
if (! session->is_error())
782
if (! session->is_error())
785
Binlog logs a string starting from session->query and having length
786
session->query_length; so we set session->query_length correctly (to not
787
log several statements in one event, when we executed only first).
788
We set it to not see the ';' (otherwise it would get into binlog
789
and Query_log_event::print() would give ';;' output).
790
This also helps display only the current query in SHOW
792
Note that we don't need LOCK_thread_count to modify query_length.
794
if (*found_semicolon &&
795
(session->query_length= (ulong)(*found_semicolon - session->query)))
796
session->query_length--;
797
DRIZZLE_QUERY_EXEC_START(session->query,
799
const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
800
/* Actually execute the query */
801
mysql_execute_command(session);
802
DRIZZLE_QUERY_EXEC_DONE(0);
760
DRIZZLE_QUERY_EXEC_START(session->query.c_str(),
762
const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
763
/* Actually execute the query */
764
mysql_execute_command(session);
765
DRIZZLE_QUERY_EXEC_DONE(0);
808
assert(session->is_error());
811
session->set_proc_info("freeing items");
812
session->end_statement();
813
session->cleanup_after_query();
771
assert(session->is_error());
775
session->set_proc_info("freeing items");
776
session->end_statement();
777
session->cleanup_after_query();