MySQL PreparedStatement Performance Issue Reproduction Report
1. Executive Summary
1.1 Issue Description
A severe performance issue was reported when MySQL processes PreparedStatement IN queries with a large number of parameters (50,000) using useServerPrepStmts=true. According to the original report, server-side prepared statements were 190-207 times slower than client-side prepared statements.
=== MySQL PreparedStatement Performance Comparison Test === Connection: mysql-prepared-test.cfsoq6muu0jv.ap-southeast-1.rds.amazonaws.com:3306/test Parameter count: 50000 Test rounds: 3
=== useServerPrepStmts=false Test Results === Total execution time: 1202ms Average execution time: 400.7ms Records returned: 0 Com_stmt_prepare: 0 -> 0
=== MySQL PreparedStatement Performance Comparison Test === Connection: mysql57-prepared-test.cfsoq6muu0jv.ap-southeast-1.rds.amazonaws.com:3306/test Parameter count: 50000 Test rounds: 3
=== useServerPrepStmts=false Test Results === Total execution time: 1800ms Average execution time: 600.0ms Records returned: 0 Com_stmt_prepare: 0 -> 0
Title: Performance regression with useServerPrepStmts=true for large IN queries appears to be fixed in MySQL 5.7.44+
Description: A previously reported performance issue where server-side prepared statements (useServerPrepStmts=true) were significantly slower than client-side prepared statements for IN queries with 50,000 parameters could not be reproduced on MySQL 5.7.44 and 8.0.43.
Original Behavior (MySQL 5.7.29):
useServerPrepStmts=true: ~27,839ms average
useServerPrepStmts=false: ~52ms average
Performance difference: 535x slower with server-side
Current Behavior (MySQL 5.7.44 / 8.0.43):
useServerPrepStmts=true: ~90-101ms average
useServerPrepStmts=false: ~400-600ms average
Performance difference: 4-6.7x faster with server-side
Request: Could the MySQL team confirm if this issue was intentionally fixed in a specific version? If so, please document the fix in the release notes for user awareness.
Report Generated: 2026-01-12 Test Executor: Kiro CLI AWS Account: 872515255872
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 1
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 1
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 1
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 1
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
mysql: [Warning] Using a password on the command line interface can be insecure. Variable_name Value innodb_buffer_pool_size 17179869184 innodb_flush_log_at_trx_commit 2
// 将 50,000 个参数拆分为 50 批,每批 1,000 个 intbatchSize=1000; for (inti=0; i < ids.size(); i += batchSize) { List<Long> batch = ids.subList(i, Math.min(i + batchSize, ids.size())); // 执行查询 }
🗃️ 方案 4: 临时表方案
1 2 3 4
CREATE TEMPORARY TABLE temp_ids (id BIGINT); INSERT INTO temp_ids VALUES (?), (?), ...; SELECT*FROM large_table WHERE id IN (SELECT id FROM temp_ids); DROP TEMPORARY TABLE temp_ids;