Parsed test spec with 2 sessions starting permutation: s1_begin s1_plan s1_open s1_fetch64 s2_insert s1_rest s1_check s1_commit step s1_begin: BEGIN ISOLATION LEVEL REPEATABLE READ; step s1_plan: EXPLAIN (COSTS OFF) SELECT id FROM bm_cont WHERE d @@ 'hit' ORDER BY lion_bm25_score(d, 'hit', 'bm_cont_d') DESC; QUERY PLAN ----------------------------------- Custom Scan (LionBm25) on bm_cont Filter: (d @@ '''hit'''::tsquery) Index: bm_cont_d (3 rows) step s1_open: DECLARE c NO SCROLL CURSOR FOR SELECT id FROM bm_cont WHERE d @@ 'hit' ORDER BY lion_bm25_score(d, 'hit', 'bm_cont_d') DESC; step s1_fetch64: DO $$ DECLARE c refcursor := 'c'; r record; BEGIN FOR i IN 1..64 LOOP FETCH c INTO r; INSERT INTO bm_cont_got (id) VALUES (r.id); END LOOP; END $$; step s2_insert: INSERT INTO bm_cont VALUES (-1, to_tsvector('simple', repeat('hit ', 300))); step s1_rest: DO $$ DECLARE c refcursor := 'c'; r record; BEGIN LOOP FETCH c INTO r; EXIT WHEN NOT FOUND; INSERT INTO bm_cont_got (id) VALUES (r.id); END LOOP; END $$; step s1_check: SELECT count(*) AS fetched, count(DISTINCT id) AS distinct_rows, bool_and(id = 101 - n) AS best_first FROM bm_cont_got; fetched|distinct_rows|best_first -------+-------------+---------- 100| 100|t (1 row) step s1_commit: COMMIT; starting permutation: s1_begin s1_plan s1_open s1_fetch64 s2_insert_below s1_rest s1_check s1_commit step s1_begin: BEGIN ISOLATION LEVEL REPEATABLE READ; step s1_plan: EXPLAIN (COSTS OFF) SELECT id FROM bm_cont WHERE d @@ 'hit' ORDER BY lion_bm25_score(d, 'hit', 'bm_cont_d') DESC; QUERY PLAN ----------------------------------- Custom Scan (LionBm25) on bm_cont Filter: (d @@ '''hit'''::tsquery) Index: bm_cont_d (3 rows) step s1_open: DECLARE c NO SCROLL CURSOR FOR SELECT id FROM bm_cont WHERE d @@ 'hit' ORDER BY lion_bm25_score(d, 'hit', 'bm_cont_d') DESC; step s1_fetch64: DO $$ DECLARE c refcursor := 'c'; r record; BEGIN FOR i IN 1..64 LOOP FETCH c INTO r; INSERT INTO bm_cont_got (id) VALUES (r.id); END LOOP; END $$; step s2_insert_below: INSERT INTO bm_cont VALUES (-2, to_tsvector('simple', repeat('hit ', 20) || 'pad pad pad pad pad')); step s1_rest: DO $$ DECLARE c refcursor := 'c'; r record; BEGIN LOOP FETCH c INTO r; EXIT WHEN NOT FOUND; INSERT INTO bm_cont_got (id) VALUES (r.id); END LOOP; END $$; step s1_check: SELECT count(*) AS fetched, count(DISTINCT id) AS distinct_rows, bool_and(id = 101 - n) AS best_first FROM bm_cont_got; fetched|distinct_rows|best_first -------+-------------+---------- 100| 100|t (1 row) step s1_commit: COMMIT; starting permutation: s1_begin s1_open_scores s2_insert_many s1_scores s1_check_scores s1_commit step s1_begin: BEGIN ISOLATION LEVEL REPEATABLE READ; step s1_open_scores: DECLARE c NO SCROLL CURSOR FOR SELECT id, lion_bm25_score(d, 'hit | pad', 'bm_cont_d') AS s FROM bm_cont WHERE d @@ 'hit | pad' ORDER BY lion_bm25_score(d, 'hit | pad', 'bm_cont_d') DESC; step s2_insert_many: INSERT INTO bm_cont SELECT 5000 + g, to_tsvector('simple', 'other') FROM generate_series(1, 3000) g; step s1_scores: DO $$ DECLARE c refcursor := 'c'; r record; BEGIN LOOP FETCH c INTO r; EXIT WHEN NOT FOUND; INSERT INTO bm_cont_got (id, s) VALUES (r.id, r.s); END LOOP; END $$; step s1_check_scores: SELECT count(*) AS fetched, count(*) FILTER (WHERE s > prev) AS out_of_order FROM (SELECT s, lag(s) OVER (ORDER BY n) AS prev FROM bm_cont_got) x; fetched|out_of_order -------+------------ 100| 0 (1 row) step s1_commit: COMMIT;