Skip to content

[fix](point-query) Refresh stale prepared short-circuit plans#63920

Merged
eldenmoon merged 1 commit into
apache:masterfrom
HonestManXin:fix_point_replace
Jun 1, 2026
Merged

[fix](point-query) Refresh stale prepared short-circuit plans#63920
eldenmoon merged 1 commit into
apache:masterfrom
HonestManXin:fix_point_replace

Conversation

@HonestManXin
Copy link
Copy Markdown
Contributor

@HonestManXin HonestManXin commented May 31, 2026

Prepared point queries cache short-circuit planner state and the associated StatementContext.
When a target table is renamed, replaced, or swapped, the cached plan may still reference stale
table metadata and reuse an outdated StatementContext, causing execution failures or incorrect
table access.

This change tracks the table name captured during planning, checks dropped/renamed/schema-changed
tables before reusing the short-circuit context, and reparses the prepared SQL to rebuild the
prepared plan with a fresh StatementContext when the cached context is stale. Bound placeholder
values and MySQL parameter types are preserved across refresh. Regression coverage is added for
rename, replace, and swap scenarios.

@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@HonestManXin
Copy link
Copy Markdown
Contributor Author

/review

@github-actions
Copy link
Copy Markdown
Contributor

OpenCode automated review failed and did not complete.

Error: Error: Token refresh failed: 401
Workflow run: https://github.com/apache/doris/actions/runs/26716337495

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@HonestManXin
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 31253 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit fc6950471e974fb948cf8fb3c0c9a0330b6c9362, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17568	4039	3990	3990
q2	q3	10763	1374	826	826
q4	4703	467	351	351
q5	7760	2231	2073	2073
q6	375	170	138	138
q7	974	810	655	655
q8	9351	1805	1681	1681
q9	7017	5029	4948	4948
q10	6452	2188	1869	1869
q11	450	276	244	244
q12	690	423	297	297
q13	18210	3322	2771	2771
q14	267	259	236	236
q15	q16	819	796	707	707
q17	926	949	834	834
q18	6850	5786	5541	5541
q19	1344	1264	1036	1036
q20	512	408	254	254
q21	5982	2559	2506	2506
q22	432	353	296	296
Total cold run time: 101445 ms
Total hot run time: 31253 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4313	4271	4277	4271
q2	q3	4562	4909	4365	4365
q4	2062	2180	1357	1357
q5	4427	4292	4720	4292
q6	255	203	142	142
q7	2002	1868	1648	1648
q8	2806	2134	2183	2134
q9	7994	8085	7968	7968
q10	4840	4812	4433	4433
q11	554	398	366	366
q12	746	756	529	529
q13	3253	3633	2989	2989
q14	321	306	282	282
q15	q16	706	731	649	649
q17	1333	1314	1305	1305
q18	7800	7338	6830	6830
q19	1145	1091	1077	1077
q20	2211	2205	1943	1943
q21	5308	4629	4455	4455
q22	503	459	402	402
Total cold run time: 57141 ms
Total hot run time: 51437 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 172374 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit fc6950471e974fb948cf8fb3c0c9a0330b6c9362, data reload: false

query5	4381	671	535	535
query6	340	220	203	203
query7	4282	569	317	317
query8	327	241	228	228
query9	8810	4132	4096	4096
query10	446	339	306	306
query11	5793	2528	2269	2269
query12	185	134	133	133
query13	1283	605	456	456
query14	6129	5535	5217	5217
query14_1	4540	4572	4499	4499
query15	212	213	180	180
query16	1033	453	436	436
query17	1133	719	585	585
query18	2635	491	379	379
query19	207	205	162	162
query20	140	131	127	127
query21	212	140	119	119
query22	13681	13716	13419	13419
query23	17091	16533	16230	16230
query23_1	16322	16349	16298	16298
query24	7385	1775	1316	1316
query24_1	1327	1334	1333	1333
query25	590	507	449	449
query26	1343	315	182	182
query27	2732	556	350	350
query28	4467	2023	2017	2017
query29	1020	651	532	532
query30	312	246	199	199
query31	1138	1090	973	973
query32	90	78	78	78
query33	566	371	312	312
query34	1185	1173	677	677
query35	776	802	713	713
query36	1407	1390	1241	1241
query37	159	109	95	95
query38	3219	3210	3128	3128
query39	943	925	892	892
query39_1	891	883	906	883
query40	237	151	138	138
query41	72	70	69	69
query42	113	112	110	110
query43	360	362	316	316
query44	
query45	221	208	202	202
query46	1128	1183	767	767
query47	2345	2336	2258	2258
query48	417	414	318	318
query49	653	510	410	410
query50	1057	365	258	258
query51	4370	4282	4277	4277
query52	108	109	98	98
query53	261	286	214	214
query54	338	292	270	270
query55	96	97	95	95
query56	337	327	314	314
query57	1462	1421	1346	1346
query58	308	282	272	272
query59	1604	1677	1439	1439
query60	336	343	340	340
query61	190	179	205	179
query62	690	658	590	590
query63	242	204	210	204
query64	2404	825	648	648
query65	
query66	1657	472	359	359
query67	29880	29561	29500	29500
query68	
query69	463	352	313	313
query70	1068	1001	1008	1001
query71	316	277	270	270
query72	2991	2726	2429	2429
query73	879	744	416	416
query74	5094	4922	4800	4800
query75	2720	2615	2281	2281
query76	2283	1170	805	805
query77	422	414	341	341
query78	12357	12347	11811	11811
query79	1478	1065	792	792
query80	1286	574	460	460
query81	500	284	240	240
query82	1325	155	121	121
query83	358	272	247	247
query84	269	147	113	113
query85	959	543	461	461
query86	452	346	326	326
query87	3434	3394	3252	3252
query88	3608	2755	2740	2740
query89	466	387	344	344
query90	1786	186	196	186
query91	187	173	141	141
query92	83	80	71	71
query93	1579	1409	870	870
query94	677	362	329	329
query95	693	479	356	356
query96	1117	792	332	332
query97	2764	2704	2620	2620
query98	231	230	228	228
query99	1194	1155	1033	1033
Total cold run time: 255543 ms
Total hot run time: 172374 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 69.70% (69/99) 🎉
Increment coverage report
Complete coverage report

@eldenmoon
Copy link
Copy Markdown
Member

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review result: no blocking issues found in this pass.

Critical checkpoint conclusions:

  • Goal and proof: The PR refreshes stale prepared short-circuit point-query plans when cached table metadata is no longer reusable. The added regression coverage exercises rename, drop/recreate, replace, swap, schema change, and string-key cases.
  • Scope and clarity: The change is focused on prepared statement context reuse and short-circuit cache invalidation, with no broad unrelated behavior changes observed.
  • Concurrency: Prepared statement state is session-scoped through ConnectContext; I did not find new shared cross-session mutable state or new locking requirements.
  • Lifecycle: Cached ShortCircuitQueryContext now checks dropped table, schema version, and table-name drift before reuse. Refresh success replaces the prepared context, and refresh failure rolls back executor/prepared state.
  • Configuration: No new configuration items.
  • Compatibility: No storage format, RPC, Thrift, or persisted metadata compatibility impact found.
  • Parallel paths: Reviewed COM_STMT_EXECUTE binding, ExecuteCommand, StmtExecutor context synchronization, PointQueryExecutor direct execution, and OlapScanNode metadata capture; the updated path appears consistently wired.
  • Special checks: The reusable check has a concrete purpose: avoiding direct execution against renamed/dropped/recreated schema/table metadata.
  • Test coverage: Regression tests were added for the main metadata-change scenarios. I did not run the test suite in this review environment.
  • Observability: Existing debug logs around refresh are sufficient for this narrow path; no new metrics appear necessary.
  • Transaction/persistence/data writes: The change affects read-side prepared point-query planning/cache reuse only; no edit log or write atomicity impact found.
  • FE/BE variable passing: No new FE-to-BE variables were introduced.
  • Performance: The fast reusable path is preserved; reparsing/replanning is limited to detected stale short-circuit contexts.

User focus: No additional user-provided review focus was specified.

Copy link
Copy Markdown
Member

@eldenmoon eldenmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eldenmoon eldenmoon merged commit 8db9a80 into apache:master Jun 1, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants