Skip to content

Commit f8af845

Browse files
committed
Improved analyze for declarative partitioning
1 parent bbedd12 commit f8af845

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.1 (unreleased)
2+
3+
- Improved `analyze` for declarative partitioning
4+
15
## 0.7.0 (2025-05-26)
26

37
- Dropped support for Ruby < 3

lib/pgslice/cli/analyze.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def analyze(table)
66
table = create_table(table)
77
parent_table = options[:swapped] ? table : table.intermediate_table
88

9-
analyze_list = parent_table.partitions + [parent_table]
9+
_, _, _, _, declarative, _ = parent_table.fetch_settings(table.trigger_name)
10+
analyze_list = declarative ? [parent_table] : (parent_table.partitions + [parent_table])
1011
run_queries_without_transaction(analyze_list.map { |t| "ANALYZE VERBOSE #{quote_table(t)};" })
1112
end
1213
end

test/pgslice_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def assert_period(period, column: "createdAt", trigger_based: false, tablespace:
119119
$conn.exec('INSERT INTO "Posts" ("' + column + '") VALUES (\'' + now.iso8601 + '\') RETURNING "Id"').first
120120

121121
run_command "analyze Posts"
122+
last_analyzed = $conn.exec("SELECT relname, EXTRACT(EPOCH FROM NOW() - last_analyze) AS last_analyzed FROM pg_stat_all_tables WHERE relname LIKE 'Posts_%'").to_a
123+
assert_equal 4, last_analyzed.size
124+
assert last_analyzed.all? { |v| v["last_analyzed"].to_f < 0.01 }
122125

123126
# TODO check sequence ownership
124127
output = run_command "swap Posts"

0 commit comments

Comments
 (0)