During our research for the memory “leak“ issue (https://github.com/arkhipov/temporal_tables/issues/24) we found out, that „hash_entry“ will not be found in function “insert_history_row” in some cases, leading to refilling “hash_entry” on every call of the function.
This issue occurs on tables with e.g. defined constraints or default values. In function “insert_history_row” the check
always evaluates to true as equalTupleDescs(*tupdesc, hash_entry->tupdesc) and equalTupleDescs(history_tupdesc, hash_entry->history_tupdesc) evaluate to false. In our cases this was because in function equalTupleDesc the check if (attr1->attnotnull != attr2->attnotnull) evaluates to false as “attr2->attnotnull” is 0, even for columns with “NOT NULL“ set.
As far as we could find out the cause seem to be the way the tuple description is copied into the “hash_entry” in function “fill_versioning_hash_entry”: “CreateTupleDescCopy” does explicitly not copy default values and constraints. Using “CreateTupleDescCopyConstr” instead does. Using “CreateTupleDescCopy” instead fix this for us:
During our research for the memory “leak“ issue (https://github.com/arkhipov/temporal_tables/issues/24) we found out, that „hash_entry“ will not be found in function “insert_history_row” in some cases, leading to refilling “hash_entry” on every call of the function.
This issue occurs on tables with e.g. defined constraints or default values. In function “insert_history_row” the check
always evaluates to true as
equalTupleDescs(*tupdesc, hash_entry->tupdesc)
andequalTupleDescs(history_tupdesc, hash_entry->history_tupdesc)
evaluate to false. In our cases this was because in functionequalTupleDesc
the checkif (attr1->attnotnull != attr2->attnotnull)
evaluates to false as “attr2->attnotnull” is 0, even for columns with “NOT NULL“ set.As far as we could find out the cause seem to be the way the tuple description is copied into the “hash_entry” in function “fill_versioning_hash_entry”: “CreateTupleDescCopy” does explicitly not copy default values and constraints. Using “CreateTupleDescCopyConstr” instead does. Using “CreateTupleDescCopy” instead fix this for us: