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

[YSQL][ASH] Metadata is not unset correctly in pl/pgsql #22382

Closed
1 task done
abhinab-yb opened this issue May 14, 2024 · 0 comments
Closed
1 task done

[YSQL][ASH] Metadata is not unset correctly in pl/pgsql #22382

abhinab-yb opened this issue May 14, 2024 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@abhinab-yb
Copy link
Contributor

abhinab-yb commented May 14, 2024

Jira Link: DB-11281

Description

CREATE OR REPLACE FUNCTION AUTOUSER (uname varchar(20))
RETURNS TEXT AS $$
BEGIN
    execute format('CREATE USER %I WITH PASSWORD %L', uname, 'myuser');
    execute format('GRANT ALL ON DATABASE mydb TO %I', uname);
    execute format('GRANT ALL ON  ALL TABLES IN SCHEMA public TO %I', uname);
    RETURN CONCAT(uname,' Created');
END;
$$ 
LANGUAGE plpgsql;

In this example, while executing execute format('CREATE USER %I WITH PASSWORD %L', uname, 'myuser');, only the post_parse_analyze hook is called where the metadata is set, but no ProcessUtility/ExecutorEnd hook is called to unset the metadata

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@abhinab-yb abhinab-yb added the area/ysql Yugabyte SQL (YSQL) label May 14, 2024
@abhinab-yb abhinab-yb self-assigned this May 14, 2024
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels May 14, 2024
abhinab-yb added a commit that referenced this issue May 22, 2024
…ements is tracking it

Summary:
ASH's query id is the same as the one present in the pg_stat_statements view. In case of
nested queries, pg_stat_statements may or may not track them, depending on the guc
`pg_stat_statements.track`. This diff tracks the nested query ids with ASH only if
pg_stat_statements is also doing it.

This diff also avoids setting the query id in the post_parse_analyze hook, because in some
cases of nested queries, only the post_parse_analyze hook is called and no subsequent
ExecutorEnd / ProcessUtility hook is called, in which case we would push the query id to the
stack but never pop it. Now, we start tracking the query id at the start of ExecutorStart /
ProcessUtility hook and stop tracking it at the end of ExecutorEnd / ProcessUtility hook or
if there is some error encountered in between.
Jira: DB-10002, DB-11281

Test Plan: ./yb_build.sh --java-test TestYbAsh#testNestedQueriesWithAsh

Reviewers: jason

Reviewed By: jason

Subscribers: hbhanawat, yql, amitanand

Differential Revision: https://phorge.dev.yugabyte.com/D34773
svarnau pushed a commit that referenced this issue May 25, 2024
…ements is tracking it

Summary:
ASH's query id is the same as the one present in the pg_stat_statements view. In case of
nested queries, pg_stat_statements may or may not track them, depending on the guc
`pg_stat_statements.track`. This diff tracks the nested query ids with ASH only if
pg_stat_statements is also doing it.

This diff also avoids setting the query id in the post_parse_analyze hook, because in some
cases of nested queries, only the post_parse_analyze hook is called and no subsequent
ExecutorEnd / ProcessUtility hook is called, in which case we would push the query id to the
stack but never pop it. Now, we start tracking the query id at the start of ExecutorStart /
ProcessUtility hook and stop tracking it at the end of ExecutorEnd / ProcessUtility hook or
if there is some error encountered in between.
Jira: DB-10002, DB-11281

Test Plan: ./yb_build.sh --java-test TestYbAsh#testNestedQueriesWithAsh

Reviewers: jason

Reviewed By: jason

Subscribers: hbhanawat, yql, amitanand

Differential Revision: https://phorge.dev.yugabyte.com/D34773
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

2 participants