Skip to content

Commit 388004e

Browse files
committed
Fix formatting and potential NULL concatenation bug
Code quality improvements: - Standardize comment formatting to include space after "--": - b3_table_pgstattuple.sql: Fix 4 comment lines - b4_btree_pgstattuple.sql: Fix 4 comment lines - l1_lock_trees.sql: Fix inline comment - v2_autovacuum_progress_and_queue.sql: Fix inline comment Bug fix: - l2_lock_trees.sql: Add ELSE clause to CASE statement to prevent NULL concatenation when level = 1, which would make the entire format() result NULL These changes ensure consistent comment formatting across SQL files and fix a subtle bug that could cause query results to be NULL.
1 parent 00b0098 commit 388004e

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

sql/b3_table_pgstattuple.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
--Table bloat (requires pgstattuple; expensive)
22

3-
--https://github.com/dataegret/pg-utils/tree/master/sql
4-
--pgstattuple extension required
5-
--WARNING: without table name/mask query will read all available tables which could cause I/O spikes
3+
-- https://github.com/dataegret/pg-utils/tree/master/sql
4+
-- pgstattuple extension required
5+
-- WARNING: without table name/mask query will read all available tables which could cause I/O spikes
66
select nspname,
77
relname,
88
pg_size_pretty(relation_size + toast_relation_size) as total_size,
@@ -22,7 +22,7 @@ from (
2222
left join pg_namespace n on (n.oid = c.relnamespace)
2323
where nspname not in ('pg_catalog', 'information_schema')
2424
and nspname !~ '^pg_toast' and relkind = 'r'
25-
--put your table name/mask here
25+
-- put your table name/mask here
2626
and relname ~ ''
2727
) t
2828
order by (toast_free_space + relation_size - (relation_size - free_space)*100/fillfactor) desc

sql/b4_btree_pgstattuple.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
--B-tree indexes bloat (requires pgstattuple; expensive)
22

3-
--https://github.com/dataegret/pg-utils/tree/master/sql
4-
--pgstattuple extension required
5-
--WARNING: without index name/mask query will read all available indexes which could cause I/O spikes
3+
-- https://github.com/dataegret/pg-utils/tree/master/sql
4+
-- pgstattuple extension required
5+
-- WARNING: without index name/mask query will read all available indexes which could cause I/O spikes
66
with data as (
77
select
88
schemaname as schema_name,
@@ -25,7 +25,7 @@ with data as (
2525
join pg_class c_table on p.relid = c_table.oid
2626
where
2727
pg_get_indexdef(p.indexrelid) like '%USING btree%'
28-
--put your index name/mask here
28+
-- put your index name/mask here
2929
and indexrelname ~ ''
3030
)
3131
select

sql/l1_lock_trees.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ with recursive l as (
2828
select (clock_timestamp() - a.xact_start)::interval(0) as ts_age,
2929
(clock_timestamp() - a.state_change)::interval(0) as change_age,
3030
a.datname,a.usename,a.client_addr,
31-
--w.obj wait_on_object,
31+
-- w.obj wait_on_object,
3232
tree.pid,replace(a.state, 'idle in transaction', 'idletx') state,
3333
lvl,(select count(*) from tree p where p.path ~ ('^'||tree.path) and not p.path=tree.path) blocked,
3434
case when tree.pid=any(tree.dl) then '!>' else repeat(' .', lvl) end||' '||trim(left(regexp_replace(a.query, e'\\s+', ' ', 'g'),100)) query

sql/l2_lock_trees.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ select
6161
format(
6262
'%s %s%s',
6363
lpad('[' || pid::text || ']', 7, ' '),
64-
repeat('.', level - 1) || case when level > 1 then ' ' end,
64+
repeat('.', level - 1) || case when level > 1 then ' ' else '' end,
6565
left(query, 1000)
6666
) as query
6767
from tree

sql/v2_autovacuum_progress_and_queue.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ with table_opts as (
3030
from pg_stat_progress_vacuum
3131
)
3232
select
33-
--vacuum_settings.oid,
33+
-- vacuum_settings.oid,
3434
coalesce(
3535
coalesce(nullif(vacuum_settings.nspname, 'public') || '.', '') || vacuum_settings.relname, -- current DB
3636
format('[something in "%I"]', p.datname)

0 commit comments

Comments
 (0)