diff --git a/db/reqlog.c b/db/reqlog.c index e20ac1bb81..ff27af7f23 100644 --- a/db/reqlog.c +++ b/db/reqlog.c @@ -1477,7 +1477,6 @@ inline void reqlog_set_sql(struct reqlogger *logger, struct string_ref *sr) put_ref(&logger->sql_ref); if (sr) { logger->sql_ref = get_ref(sr); - reqlog_logf(logger, REQL_INFO, "sql=%s", string_ref_cstr(logger->sql_ref)); } } @@ -2189,6 +2188,9 @@ void reqlog_end_request(struct reqlogger *logger, int rc, const char *callfunc, long_request_thresh = long_request_ms; } + if (logger->sql_ref) + reqlog_logf(logger, REQL_INFO, "sql=%s", string_ref_cstr(logger->sql_ref)); + if (logger->durationus >= M2U(long_request_thresh)) { if (logger->clnt) { log_params(logger); diff --git a/lua/sp.c b/lua/sp.c index 869c3284b4..df6ad7c911 100644 --- a/lua/sp.c +++ b/lua/sp.c @@ -2200,16 +2200,6 @@ static int dbstmt_bind_int(Lua lua, dbstmt_t *dbstmt) return stmt_bind(lua, dbstmt->stmt); } -static void lua_set_clnt_sql(struct sqlclntstate *clnt, char *sql) { - if (!clnt || !sql) return; - clnt->sql = sql; -} - -static void lua_set_clnt_origin(struct sqlclntstate *clnt, char *origin) { - if (!clnt || !origin) return; - clnt->origin = origin; -} - static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt, struct sql_state *rec, int flags) { @@ -2225,7 +2215,6 @@ static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt, print events (see reqlog_logv_int) in the logger. */ reqlog_reset_logger(sp->thd->logger); reqlog_set_origin(sp->thd->logger, "%s", sp->clnt->origin); - lua_set_clnt_sql(sp->clnt, (char *)sql); retry: memset(&err, 0, sizeof(struct errstat)); if (sp->initial) { @@ -2238,6 +2227,7 @@ static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt, sp->rc = get_prepared_stmt_try_lock(sp->thd, sp->clnt, rec_ptr, &err, flags & ~PREPARE_RECREATE); } sp->initial = 0; + reqlog_set_sql(sp->thd->logger, create_string_ref(sql)); if ((sp->rc == SQLITE_PERM) && (maxRetries != 0) && ((maxRetries == -1) || (nRetry++ < maxRetries))) { int sleepms = ATOMIC_LOAD32(gbl_lua_prepare_retry_sleep);