Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the wrong statistic of timestamp data type after import. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

higuchi-daisuke
Copy link

Hi,

I found the problem when trying import the statistics of timestamp data type.
The values of the statistics have changed before and after the import.

[How to reproduce]

create extension pg_dbms_stats ;
create table timestamp_test(c1 timestamp);
insert into timestamp_test values ('2020-10-01 10:00:0.55555'), ('2020-10-01 10:00:0.55555'), ('2020-10-01 10:00:0.55555');
analyze timestamp_test;
select most_common_vals from dbms_stats.stats where tablename = 'timestamp_test'; -- (1) before import, the result is {"2020-10-01 10:00:00.55555"}
\i /home/postgres/pgsql/share/doc/extension/export_effective_stats-12.sql.sample
select dbms_stats.import_database_stats('/home/postgres/export_stats.dmp');
select most_common_vals from dbms_stats.stats where tablename = 'timestamp_test'; -- (2) after import, the result is {"2020-10-01 10:00:01"}.

As you see, milliseconds of the statistic have been rounded off.

[Investigation]
As my investigation, "0" is always passed to the fifth argument ("typmod") of ReadArrayBinary in dbms_stats_array_recv.
I think the value which ReceiveFunctionCall() passes should be used.

        ReadArrayBinary(buf, nitems,
                                        &my_extra->proc, typioparam, 0,
                                        typlen, typbyval, typalign,
                                        dataPtr, nullsPtr,
                                        &hasnulls, &nbytes);

This PR is fix this issue and add test for master branch.

Regards,
Daisuke Higuchi

'0' is always passed to the value of ReadArrayBinary argument 'typmod'.
As a result, incorrect value statistics are imported on somebdata types
after importing statistics. For example, in the timestamp data type,
the millisecond value is rounded off.
In this commit, dbms_stats_array_recv gets the value of 'typmod' and
passes it to ReadArrayBinary.
@kasaharatt
Copy link

Hi.

Yeah, I think it's a reasonable fix.
The time and interval types are also affected by this bug...

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.

2 participants