> After sleeping on this, I realized that we can simplify things a bit by
> using merge_toast_reloptions() for manual VACUUM, too. I've added a new
> 0007 for that. The autovacuum fix now lives in 0008.
Makes sense to me. A few comments:
1/ 0007 adds merge_toast_reloptions(), and for each option it calls
find_reloption() to get the type and default. find_reloption() scans the entire
relOpts[]. The options don't change, so it's just repeating the same work
every time, which also includes strcmp to match the options by name.
find_reloption() already runs initialize_reloptions(), so could
initialize_reloptions()
also build a small table of the options a toast table inherits from
its main table.
merge_toast_reloptions() then just iterates that table and no longer needs to
call find_reloption() in the scan.
This would help most when pg_stat_autovacuum_scores calls
merge_toast_reloptions()
for every toast table in its list, which occurs in 0008.
2/ There are three spots that repeat the work for a toast table,
extractRelOptions() followed by a table_toast_map lookup
and a merge_toast_reloptions().
For example, when do_autovacuum() performs the pass on the toast
tables:
```
/*
- * fetch reloptions -- if this toast table does not
have them, try the
- * main rel
+ * fetch reloptions -- merge any unset options from the main rel
*/
relopts = (StdRdOptions *) extractRelOptions(tuple,
pg_class_desc, NULL);
if (relopts)
free_relopts = true;
- else
- {
- av_relation *hentry;
- bool found;
-
- hentry = hash_search(table_toast_map, &relid,
HASH_FIND, &found);
- if (found)
- relopts = &hentry->ar_reloptions;
- }
+ hentry = hash_search(table_toast_map, &relid,
HASH_FIND, &found);
+ if (found)
+ relopts = merge_toast_reloptions(relopts,
&hentry->ar_reloptions);
```
as well as table_recheck_autovac() and pg_stat_get_autovacuum_scores().
The job here is to find the "effective" toast options, and it might be
worthwhile
to turn this into a single helper for clarity.
--
Sami Imseih
Amazon Web Services (AWS)