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

Optimized pgstat_init_function_usage/pg_newlocale_from_collation #188

Conversation

ParikshitSarode
Copy link
Contributor

@ParikshitSarode ParikshitSarode commented Aug 18, 2023

Description

In per row execution, when we call func like varncmp or varcmp inside fmgr_security_definer, it'll go through pgstat_init_function_usage in pg_stat_statements and pgstat_init_function_usage did a searchcache everytime when the function is called, this call is avoided in this update. Optimized both the functions by reducing system cache search every time by storing the previous cached values in pgstat_init_function_usage and pg_newlocale_from_collation.
Query execution time reduction is noticed after optimisation on varchar index.

Singned-off-by: Parikshit Sarode [email protected]

Issues Resolved

Optimised function pgstat_init_function_usage and pg_newlocale_from_collation by reducing the SearchSysCache1 calls.

Results

On database with 50000 entries including columns of datatypes -int, varchar, date, money , following results were obtained:

select * from <table> where <column name> < '<varchar%%>'
before results - 4096:1:3227:3227.0:0.3 (15427 rows affected)
after results - 4096:1:2735:2735.0:0.4 (15432 rows affected)

select * from <table> where <column name> > '<varchar>'
before results - 4096:1:10227:10227.0:0.1 (50000 rows affected)
after results - 4096:1:9923:9923.0:0.1 (50000 rows affected)

BABEL-4300

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

src/backend/utils/activity/pgstat_function.c Outdated Show resolved Hide resolved
src/backend/utils/fmgr/fmgr.c Outdated Show resolved Hide resolved
src/backend/utils/activity/pgstat_function.c Outdated Show resolved Hide resolved
@@ -40,8 +40,6 @@ int pgstat_track_functions = TRACK_FUNC_OFF;
*/
static instr_time total_func_time;

pre_function_call_hook_type pre_function_call_hook = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not delete this hook definition, as it's a community PG code

@@ -1534,6 +1537,11 @@ pg_newlocale_from_collation(Oid collid)
}

cache_entry = lookup_collation_cache(collid, false);

if (prev_cache && prev_cache->collid == collid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should wrap those code into a hook, and put the impl into babel code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here caching the very previous call using global pointer to avoid hash search. Creating a hook for this may be unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

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

We should try our best to make minimal change on PG side

}

prev_cache->collid = cache_entry->collid;
prev_cache->locale = cache_entry->locale;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this part into babel specific too

forestkeeper
forestkeeper previously approved these changes Sep 11, 2023
Copy link
Contributor

@forestkeeper forestkeeper left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@forestkeeper forestkeeper left a comment

Choose a reason for hiding this comment

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

LGTM

@forestkeeper forestkeeper merged commit c7572cd into babelfish-for-postgresql:BABEL_3_X_DEV__PG_15_X Sep 26, 2023
Sairakan pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 16, 2023
…elfish-for-postgresql#188)

* Optimize pgstat_init_function_usage/pg_newlocale_from_collation  function in creating index

Signed-off-by: Parikshit Sarode <[email protected]>
Task: BABEL-4300
priyansx pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 22, 2023
…elfish-for-postgresql#188)

* Optimize pgstat_init_function_usage/pg_newlocale_from_collation  function in creating index

Signed-off-by: Parikshit Sarode <[email protected]>
Task: BABEL-4300
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.

3 participants