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] prefix_length from distinct pushdown should only encompass distinct target columns #17607

Closed
1 task done
tanujnay112 opened this issue May 30, 2023 · 1 comment
Closed
1 task done
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue

Comments

@tanujnay112
Copy link
Contributor

tanujnay112 commented May 30, 2023

Jira Link: DB-6736

Description

Consider the following query:

create table sample(r1 int, r2 int, r3 int, primary key(r1 asc, r2 asc, r3 asc));
insert into sample select i/100, (i/10) %10, i % 10 from generate_series(1,999) i;
set yb_debug_log_docdb_requests to true;
explain analyze select distinct(r1,r2) from sample where r3 >= 10;

We see that this results in the following output in the postgres logs:

I0530 12:14:33.717185 1144820544 pg_session.cc:246] Applying operation: { READ active: 1 read_time: { read: <invalid> local_limit: <invalid> global_limit: <invalid> in_txn_limit: <invalid> serial_no: 0 } request: client: YQL_CLIENT_PGSQL stmt_id: 4843110688 schema_version: 0 targets { column_id: 10 } targets { column_id: 11 } targets { column_id: 12 } targets { column_id: -8 } column_refs { ids: 10 ids: 11 ids: 12 } is_forward_scan: 1 is_aggregate: 0 limit: 1024 return_paging_state: 1 ysql_catalog_version: 113 table_id: "000033f1000030008000000000004100" condition_expr { condition { op: QL_OP_AND operands { condition { op: QL_OP_GREATER_THAN_EQUAL operands { column_id: 12 } operands { value { int32_value: 10 } } } } } } upper_bound { key: "7E007E21" is_inclusive: 1 } col_refs { column_id: 10 attno: 1 } col_refs { column_id: 11 attno: 2 } col_refs { column_id: 12 attno: 3 } partition_key: "007E21" prefix_length: 3 size_limit: 0 }

You can see that the prefix_length field here is 3. Even if we execute the query explain analyze select distinct(r1) from sample where r3 >= 10;, the prefix length remains the same. If we execute explain analyze select distinct(r1) from sample where r2 >= 10;. The prefix length goes down to 2.

This all suggests that we are using the filter columns to compute the distinct prefix length when we really should only be taking the distinct targets into account. The prefix length should be 2 for the initial example and 1 for the very last example.

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

  • I confirm this issue does not contain any sensitive information.
@vbalvida
Copy link
Contributor

Resolved by #17872

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/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants