[YSQL] QPM clock LRU can return an empty slot after a reset, and the next insert crashes
Author: bmckennaahCreated Sep 18, 2026Updated Sep 18, 2026
Labelskind/bugarea/ysqlpriority/medium
Jira Link: DB-23651
Description
Repro:
reset all;
SET yb_pg_stat_plans_max_cache_size = 3; -- postmaster GUC; set in ysql_pg.conf / tserver flag
SET yb_pg_stat_plans_cache_replacement_algorithm = simple_clock_lru;
SELECT yb_pg_stat_plans_reset(NULL, NULL, NULL, NULL);
-- Fill slots 0,1,2 (A,B,C)
SELECT yb_pg_stat_plans_insert(1,1,1,1, 'h','p', now(), now(), 1, 1);
SELECT yb_pg_stat_plans_insert(1,1,1,2, 'h','p', now(), now(), 1, 1);
SELECT yb_pg_stat_plans_insert(1,1,1,3, 'h','p', now(), now(), 1, 1);
-- Eviction sweep: clears referenced on B,C; replaces A with D; clockHand = 1
SELECT yb_pg_stat_plans_insert(1,1,1,4, 'h','p', now(), now(), 1, 1);
-- Hole at C's slot (2), not at clockHand
SELECT yb_pg_stat_plans_reset(1, 1, 1, 3);
-- Steals unreferenced B at slot 1; hole at 2 remains
SELECT yb_pg_stat_plans_insert(1,1,1,5, 'h','p', now(), now(), 1, 1);
-- HASH_ENTER makes max+1; clockHand on the hole → old code SIGSEGV
SELECT yb_pg_stat_plans_insert(1,1,1,6, 'h','p', now(), now(), 1, 1);
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
- I confirm this issue does not contain any sensitive information.
Source: yugabyte/yugabyte-db