My understanding of server-side prepared statements is that they are tied to a client session and should be reused for similar requests.
However, when I look at prepared_statements_instances
I can see the same SQL_TEXT
multiple times for the same OWNER_THREAD_ID
. It's notable that COUNT_EXECUTE
for these statements vary (and greater than 1).
Am I missing something? Why the same statement is not reused?
SELECT
OWNER_THREAD_ID,
STATEMENT_ID,
STATEMENT_NAME,
COUNT_EXECUTE,
COUNT_REPREPARE,
TIMER_PREPARE,
AVG_TIMER_EXECUTE,
SQL_TEXT
FROM prepared_statements_instance
OWNER_THREAD_ID: 123
STATEMENT_ID: 28
STATEMENT_NAME: NULL
COUNT_EXECUTE: 104
COUNT_REPREPARE: 0
TIMER_PREPARE: 111534000
AVG_TIMER_EXECUTE: 198759000
SQL_TEXT: select id from products WHERE id=?
***************************
OWNER_THREAD_ID: 123
STATEMENT_ID: 40
STATEMENT_NAME: NULL
COUNT_EXECUTE: 23
COUNT_REPREPARE: 0
TIMER_PREPARE: 111522000
AVG_TIMER_EXECUTE: 198435000
SQL_TEXT: select id from products WHERE id=?
driver settings:
useServerPrepStmts=true, cachePrepStmts=true
question from:
https://stackoverflow.com/questions/66054966/duplicated-prepared-statements-in-mysql-prepared-statements-instances 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…