Skip to content

Commit bea97cd

Browse files
committed
Improve test coverage in bump.c
There were no callers of BumpAllocLarge() in the regression tests, so here we add a sort with a tuple large enough to use that path in bump.c. Also, BumpStats() wasn't being called, so add a test to sysviews.sql to call pg_backend_memory_contexts() while a bump context exists in the backend. Reported-by: Andres Freund Discussion: https://postgr.es/m/20240414223305.m3i5eju6zylabvln@awork3.anarazel.de
1 parent 768ceee commit bea97cd

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/test/regress/expected/sysviews.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ select name, ident, parent, level, total_bytes >= free_bytes
2828
TopMemoryContext | | | 0 | t
2929
(1 row)
3030

31+
-- We can exercise some MemoryContext type stats functions. Most of the
32+
-- column values are too platform-dependant to display.
33+
-- Ensure stats from the bump allocator look sane. Bump isn't a commonly
34+
-- used context, but it is used in tuplesort.c, so open a cursor to keep
35+
-- the tuplesort alive long enough for us to query the context stats.
36+
begin;
37+
declare cur cursor for select left(a,10), b
38+
from (values(repeat('a', 512 * 1024),1),(repeat('b', 512),2)) v(a,b)
39+
order by v.a desc;
40+
fetch 1 from cur;
41+
left | b
42+
------------+---
43+
bbbbbbbbbb | 2
44+
(1 row)
45+
46+
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
47+
from pg_backend_memory_contexts where name = 'Caller tuples';
48+
name | parent | ?column? | total_nblocks | ?column? | free_chunks
49+
---------------+----------------+----------+---------------+----------+-------------
50+
Caller tuples | TupleSort sort | t | 3 | t | 0
51+
(1 row)
52+
53+
rollback;
3154
-- At introduction, pg_config had 23 entries; it may grow
3255
select count(*) > 20 as ok from pg_config;
3356
ok

src/test/regress/expected/tuplesort.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,19 @@ ORDER BY ctid DESC LIMIT 5;
343343
(5 rows)
344344

345345
ROLLBACK;
346+
----
347+
-- test sorting of large datums VALUES
348+
----
349+
-- Ensure the order is correct and values look intact
350+
SELECT LEFT(a,10),b FROM
351+
(VALUES(REPEAT('a', 512 * 1024),1),(REPEAT('b', 512 * 1024),2)) v(a,b)
352+
ORDER BY v.a DESC;
353+
left | b
354+
------------+---
355+
bbbbbbbbbb | 2
356+
aaaaaaaaaa | 1
357+
(2 rows)
358+
346359
----
347360
-- test forward and backward scans for in-memory and disk based tuplesort
348361
----

src/test/regress/sql/sysviews.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ select count(*) >= 0 as ok from pg_available_extensions;
1717
select name, ident, parent, level, total_bytes >= free_bytes
1818
from pg_backend_memory_contexts where level = 0;
1919

20+
-- We can exercise some MemoryContext type stats functions. Most of the
21+
-- column values are too platform-dependant to display.
22+
23+
-- Ensure stats from the bump allocator look sane. Bump isn't a commonly
24+
-- used context, but it is used in tuplesort.c, so open a cursor to keep
25+
-- the tuplesort alive long enough for us to query the context stats.
26+
begin;
27+
declare cur cursor for select left(a,10), b
28+
from (values(repeat('a', 512 * 1024),1),(repeat('b', 512),2)) v(a,b)
29+
order by v.a desc;
30+
fetch 1 from cur;
31+
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
32+
from pg_backend_memory_contexts where name = 'Caller tuples';
33+
rollback;
34+
2035
-- At introduction, pg_config had 23 entries; it may grow
2136
select count(*) > 20 as ok from pg_config;
2237

src/test/regress/sql/tuplesort.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ FROM abbrev_abort_uuids
146146
ORDER BY ctid DESC LIMIT 5;
147147
ROLLBACK;
148148

149+
----
150+
-- test sorting of large datums VALUES
151+
----
152+
153+
-- Ensure the order is correct and values look intact
154+
SELECT LEFT(a,10),b FROM
155+
(VALUES(REPEAT('a', 512 * 1024),1),(REPEAT('b', 512 * 1024),2)) v(a,b)
156+
ORDER BY v.a DESC;
157+
149158
----
150159
-- test forward and backward scans for in-memory and disk based tuplesort
151160
----

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy