On Sat, Mar 19, 2022 at 1:18 PM Dong Wook Lee <sh95...@gmail.com> wrote:
>
> > Well, my guess is that you basically just care about being able to
> > detect if there is free space in the map or not, which goes down to
> > detecting if pg_freespace() returns 0 or a number strictly higher than
> > 0, so wouldn't it be enough to stick some > 0 in your test queries?
>
> I edited the previous patch file.
> Am I correct in understanding that?
>

I think what Michael meant is something like attached.

Regards,

--
Fabrízio de Royes Mello
diff --git a/contrib/pg_freespacemap/Makefile b/contrib/pg_freespacemap/Makefile
index da40b80c7c..2d525a1284 100644
--- a/contrib/pg_freespacemap/Makefile
+++ b/contrib/pg_freespacemap/Makefile
@@ -10,6 +10,8 @@ DATA = pg_freespacemap--1.1.sql pg_freespacemap--1.1--1.2.sql \
 	pg_freespacemap--1.0--1.1.sql
 PGFILEDESC = "pg_freespacemap - monitoring of free space map"
 
+REGRESS = pg_freespacemap
+
 ifdef USE_PGXS
 PG_CONFIG = pg_config
 PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/pg_freespacemap/expected/pg_freespacemap.out b/contrib/pg_freespacemap/expected/pg_freespacemap.out
new file mode 100644
index 0000000000..9bf8055247
--- /dev/null
+++ b/contrib/pg_freespacemap/expected/pg_freespacemap.out
@@ -0,0 +1,36 @@
+CREATE EXTENSION pg_freespacemap;
+CREATE TABLE t1(c1 int);
+INSERT INTO t1 VALUES (generate_series(1, 1000));
+VACUUM t1;
+SELECT blkno, avail > 0 AS exists FROM pg_freespace('t1');
+ blkno | exists 
+-------+--------
+     0 | f
+     1 | f
+     2 | f
+     3 | f
+     4 | t
+(5 rows)
+
+DELETE FROM t1 WHERE c1 <= 10;
+VACUUM t1;
+SELECT blkno, avail > 0 AS exists FROM pg_freespace('t1');
+ blkno | exists 
+-------+--------
+     0 | t
+     1 | f
+     2 | f
+     3 | f
+     4 | t
+(5 rows)
+
+SELECT freespace > 0 FROM pg_freespace('t1', 0) AS freespace;
+ ?column? 
+----------
+ t
+(1 row)
+
+SELECT * FROM pg_freespace('t1', -1);
+ERROR:  invalid block number
+SELECT * FROM pg_freespace('t1', 4294967295);
+ERROR:  invalid block number
diff --git a/contrib/pg_freespacemap/sql/pg_freespacemap.sql b/contrib/pg_freespacemap/sql/pg_freespacemap.sql
new file mode 100644
index 0000000000..f416a29f12
--- /dev/null
+++ b/contrib/pg_freespacemap/sql/pg_freespacemap.sql
@@ -0,0 +1,17 @@
+CREATE EXTENSION pg_freespacemap;
+
+CREATE TABLE t1(c1 int);
+
+INSERT INTO t1 VALUES (generate_series(1, 1000));
+VACUUM t1;
+
+SELECT blkno, avail > 0 AS exists FROM pg_freespace('t1');
+
+DELETE FROM t1 WHERE c1 <= 10;
+VACUUM t1;
+
+SELECT blkno, avail > 0 AS exists FROM pg_freespace('t1');
+SELECT freespace > 0 FROM pg_freespace('t1', 0) AS freespace;
+
+SELECT * FROM pg_freespace('t1', -1);
+SELECT * FROM pg_freespace('t1', 4294967295);

Reply via email to