Skip to content

[minior fix]: adjust the projection statistics - #7428

Merged
liukun4515 merged 3 commits into
apache:mainfrom
liukun4515:fix_statistics_plan
Aug 31, 2023
Merged

liukun4515 merged 3 commits into
apache:mainfrom
liukun4515:fix_statistics_plan

Conversation

@liukun4515

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

  • support total_byte_size use the primitive_size of the datatype
  • if column of projection can't get the primitive_size, use the child statistic as statistics of the projection

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions Bot added the core Core DataFusion crate label Aug 28, 2023
@liukun4515
liukun4515 force-pushed the fix_statistics_plan branch from 5dcb74a to 5aaa677 Compare August 28, 2023 02:13
@liukun4515
liukun4515 requested review from alamb and jackwener August 28, 2023 02:13

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @liukun4515

Comment on lines +445 to +447
// TODO stats: knowing the type of the new columns we can guess the output size
// If we can't get the exact statistics for the project
// Before we get the exact result, we just use the child status

@jackwener jackwener Aug 28, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can add a future ticket about statistic derive. We need a method to handle Unknown statistic status of Expression

I'm busy recently, if I have time, I will investigate this problem.

@liukun4515

Copy link
Copy Markdown
Contributor Author

Some plan changes, I will find time to check them.

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Aug 28, 2023
@liukun4515

Copy link
Copy Markdown
Contributor Author

@jackwener PTAL again, the sql test cases changed.
I think the changes is reasonable. After this changes the left and right projection have the statistics to determine the order of join

----CoalesceBatchesExec: target_batch_size=4096
------HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(join_t1.t1_id + UInt32(12)@2, join_t2.t2_id + UInt32(1)@1)]
--------CoalescePartitionsExec
----ProjectionExec: expr=[t1_id@2 as t1_id, t1_name@3 as t1_name, join_t1.t1_id + UInt32(12)@4 as join_t1.t1_id + UInt32(12), t2_id@0 as t2_id, join_t2.t2_id + UInt32(1)@1 as join_t2.t2_id + UInt32(1)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

after this pr, the t1 and t2 has the statistics in the projection exe.

The table of t2 project the t2_id, the table of t1 project the t1_id and t1_name, hence the cost of t1 is greater than t2.

Collect the left in the join, use the t2 as the building table.

// TODO stats: knowing the type of the new columns we can guess the output size
// If we can't get the exact statistics for the project
// Before we get the exact result, we just use the child status
total_byte_size: stats.total_byte_size,

@Dandandan Dandandan Aug 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If type or output has changed stats.is_exact will not be true anymore (for total_byte_size).

@jackwener jackwener Aug 28, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think they are different things.

stats.is_exact is for the whole statistic. Current num_rows is exact.
Maybe we need add Unknow status for total_byte_size. so we just to make total_byte_size None

such as Presto:

PlanNodeStatsEstimate UNKNOWN. It's present `Unknown` for whole statistic.

SymbolStatsEstimate UNKNOWN. It's present `Unknown` for single expr statistic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm I think you're right.
The is_exact is currently a bit confusing though, I think it would be nice if we have a exact/inexact specifier for both row/byte statistics.

// TODO stats: knowing the type of the new columns we can guess the output size
// If we can't get the exact statistics for the project
// Before we get the exact result, we just use the child status
total_byte_size: stats.total_byte_size,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
total_byte_size: stats.total_byte_size,
total_byte_size: None,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you means we use the None or unknow as the total_byte_size, if we can't estimate the total_byte_size?
But it will lost the size information in side, I mean use the child's statistics directly.

cc @jackwener

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, because it will cause inaccuracy to use child's statistics directly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we might need to add exactness information (is_exact) to total_byte_size as well to prevent not propagating some (inaccurate) information about the size.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is fine to leave it inaccurate for now, as AFAIK we don't rely on exact information about total_byte_size like we do for num_rows statistics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we can't set the tota_byte_size to none or default value, if we can't get the exact information.
Now i just follow the information from the child node, that is the best choice i can find.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cc @Dandandan @jackwener any comments for this
If there is no comments for this, i will merged this pr after 24h.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants