Skip to content

Add the option to record history or not#31

Open
Vlasdislav wants to merge 6 commits into
open-gpdb:masterfrom
Vlasdislav:want_to_save_history
Open

Add the option to record history or not#31
Vlasdislav wants to merge 6 commits into
open-gpdb:masterfrom
Vlasdislav:want_to_save_history

Conversation

@Vlasdislav

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new configuration option to control whether gp_relsizes_stats writes collected size data into the table_sizes_history table, enabling users to disable history persistence while still collecting current stats.

Changes:

  • Added a new boolean GUC gp_relsizes_stats.want_to_save_history (default false) and used it to gate history-table refresh.
  • Updated regression SQL/expected outputs to cover enabling/disabling history writes.
  • Updated README configuration table to document the new parameter.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/gp_relsizes_stats.c Adds want_to_save_history GUC and conditionally calls update_table_sizes_history().
test/sql/gp_relsizes_stats.sql Extends regression test script to toggle and validate history writing behavior.
test/expected/gp_relsizes_stats.out Updates expected regression output for the new SQL statements and assertions.
README.md Documents the new gp_relsizes_stats.want_to_save_history configuration option.
Comments suppressed due to low confidence (1)

test/sql/gp_relsizes_stats.sql:109

  • Grammar in the test comment: "history don't write" is ungrammatical and a bit unclear. Consider changing it to something like "history is not written" / "history is not saved" to make the intent unambiguous.
-- Default is want_to_save_history = off — history don't write

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gp_relsizes_stats.c Outdated
Comment on lines +424 to +429
if (want_to_save_history) {
retcode = update_table_sizes_history();
if (retcode < 0) {
error = "relsizes_database_stats_job: updating tables sizes history table failed";
goto finish_spi;
}
Comment thread src/gp_relsizes_stats.c Outdated
DefineCustomBoolVariable("gp_relsizes_stats.enabled", "Enable main background worker flag", NULL, &enabled, false,
PGC_SIGHUP, GUC_NOT_IN_SAMPLE, NULL, NULL, NULL);
DefineCustomBoolVariable("gp_relsizes_stats.want_to_save_history", "Enable saving table sizes to history table", NULL, &want_to_save_history, false,
PGC_SIGHUP, GUC_NOT_IN_SAMPLE, NULL, NULL, NULL);
Comment thread test/sql/gp_relsizes_stats.sql Outdated
Comment on lines +109 to +115
-- Default is want_to_save_history = off — history don't write
SELECT relsizes_stats_schema.relsizes_collect_stats_once();
SELECT count(*) FROM relsizes_stats_schema.table_sizes_history
WHERE relname = 't_history_test';

-- Enable option - history should write
SET gp_relsizes_stats.want_to_save_history = on;
Comment thread README.md
@@ -22,12 +41,13 @@ make && make install

### Confguration
@Vlasdislav Vlasdislav changed the title Feat: Added the option to record history or not Add the option to record history or not May 27, 2026
Comment thread src/gp_relsizes_stats.c Outdated
DefineCustomBoolVariable("gp_relsizes_stats.save_history",
"Enable saving table sizes to history table.",
NULL, &save_history, false,
PGC_USERSET, 0, NULL, NULL, NULL);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USERSET is to low for this option. Probably should be SIGHUP

@Smyatkin-Maxim Smyatkin-Maxim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few critical problems here to be fixed.

Also while reviewing this PR I've noticed that there might be another problem. My understanding is that the main BG worker doesn't respond to SIGHUP. We need to write a small handler for that and reload parameters in a single point (I think right before checking for gp_relsizes_stats.enabled in main worker is the best spot).
Let's create a separate PR with this, and then get back to this one. Cuz it makes no sense writing save_history option w/o working sighup

Comment thread src/gp_relsizes_stats.c
*/
static void get_stats_for_databases(Oid *databases_oids, int databases_cnt, bool fast) {
static void get_stats_for_databases(Oid *databases_oids, int databases_cnt, bool fast, bool save_history) {
for (int i = 0; i < databases_cnt; ++i) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only here I'd load save_history GUC and pass it to the worker, so that all databases are dumped consistently with or without history. This would eliminate the case when one database is dumped with history and another without.
I think that's the only place where we read from global GUC variable. And run_database_stats_worker and relsizes_database_stats_job are the only places where we have to look for the local copy of this GUC and never look for the global variable.

Comment thread src/gp_relsizes_stats.c
BackgroundWorkerUnblockSignals();

BackgroundWorkerInitializeConnectionByOid(wa.s.db, InvalidOid);
ProcessConfigFile(PGC_SIGHUP);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's bad. At the very least it's expensive and should always be guarded by something like if (got_sighup) or if (ConfigReloadPending) or something similar. But in this specific case it breaks the whole logic behind the local variable - it simply ignores it and reads from config.
This code should be removed and local variable shold be used (via DbWorkerArg struct) as proposed in my another comment, and maybe you need the ProcessConfigFile in another place (in case the config reload is pending)

Comment thread src/gp_relsizes_stats.c
PGC_SIGHUP, GUC_NOT_IN_SAMPLE, NULL, NULL, NULL);
DefineCustomBoolVariable("gp_relsizes_stats.save_history",
"Enable saving table sizes to history table.",
NULL, &save_history, false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't be false by default. It was true before and the expected behavior should not change this way. Let it be true by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants