Skip to content

Preferred write partitioning threshold#6920

Merged
sopel39 merged 4 commits intotrinodb:masterfrom
skrzypo987:skrzypo/019-preferred-writes-threshold
Mar 8, 2021
Merged

Preferred write partitioning threshold#6920
sopel39 merged 4 commits intotrinodb:masterfrom
skrzypo987:skrzypo/019-preferred-writes-threshold

Conversation

@skrzypo987
Copy link
Copy Markdown
Member

No description provided.

@cla-bot cla-bot bot added the cla-signed label Feb 16, 2021
@skrzypo987 skrzypo987 requested a review from sopel39 February 16, 2021 14:33
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To be honest I have no idea where to put it here, so it landed at the beginning.

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.

@martint suggestions?

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.

Move it before or after reorder joins is applied. The assumption is that for reorder joins we should have the most accurate stats:

  • PredicatePushDown has been run with useTableProperties
  • later in the planning exchange nodes are added which might confuse stats.

Please add a comment why there.

@skrzypo987 skrzypo987 added the WIP label Feb 16, 2021
@skrzypo987
Copy link
Copy Markdown
Member Author

Docs still missing

@tooptoop4
Copy link
Copy Markdown
Contributor

@skrzypo987 does this fix #6570 ?

@skrzypo987
Copy link
Copy Markdown
Member Author

@skrzypo987 does this fix #6570 ?

I am afraid if enabling use_preferred_write_partitioning does not work then this will not work either

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from d8962f2 to e896ea3 Compare February 17, 2021 09:41
@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from e896ea3 to 7c5beac Compare February 22, 2021 08:18
@skrzypo987
Copy link
Copy Markdown
Member Author

I noticed that use-preferred-write-partitioning is not mentioned in the docs, just in release notes. Should this follow the same pattern?

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from 7c5beac to b1b1c3a Compare February 22, 2021 09:44
@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from b1b1c3a to 9a65ec1 Compare February 22, 2021 10:25
@skrzypo987 skrzypo987 removed the WIP label Feb 22, 2021
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.

Would it be possible to make the configuration toggle a little bit automatic?
I.e. how is the user going to determine whether they want to set this?
If this depends e.g. on number of partitions vs number of nodes, we could encode this reasoning within server's logic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The idea was to leave it backward-compatible (0 as the default value) and let the user decide the threshold based on his/her workload if necessary.
However making this more "intelligent" is not a bad idea. The question is whether we want to do it here or as a follow-up.

Copy link
Copy Markdown
Member

@sopel39 sopel39 Feb 23, 2021

Choose a reason for hiding this comment

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

when number of written or when the number of written? I'm not native, but I think the latter is correct

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.

If this depends e.g. on number of partitions vs number of nodes, we could encode this reasoning within server's logic

This doesn't really depend on number of workers. The hard limit is hive.max-partitions-per-writers which is independent of workers.

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch 3 times, most recently from 7cc4119 to 929feb6 Compare February 23, 2021 09:09
Copy link
Copy Markdown
Member

@sopel39 sopel39 Feb 23, 2021

Choose a reason for hiding this comment

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

when number of written or when the number of written? I'm not native, but I think the latter is correct

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.

If this depends e.g. on number of partitions vs number of nodes, we could encode this reasoning within server's logic

This doesn't really depend on number of workers. The hard limit is hive.max-partitions-per-writers which is independent of workers.

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 suggest to set it to some default value, e.g: 50. This should:

  • make preferred partitioning to be used when there is full table CTAS with more than 50 partitions
  • provide good concurrency (>50) for preferred partitioning
  • mitigate hive writer partition limit (100)
  • provide good concurrency for inserts into single partition

WDYT: @findepi @willmostly ?

@sopel39
Copy link
Copy Markdown
Member

sopel39 commented Feb 23, 2021

I noticed that use-preferred-write-partitioning is not mentioned in the docs, just in release notes. Should this follow the same pattern?

Nope. Both should be documented.

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch 3 times, most recently from 6d5fd05 to 3246266 Compare February 25, 2021 10:29
@skrzypo987
Copy link
Copy Markdown
Member Author

Added docs and updated the code.
Things still pending:

  • Default threshold value
  • Where to put the PreferWritePartitioning class in the optimizer (or leave it as it is)

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.

mechansm -> optimization

Elaborate more what partitions it refers to.

Copy link
Copy Markdown
Member

@sopel39 sopel39 Feb 25, 2021

Choose a reason for hiding this comment

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

Make sure it's possible to force preferred partitioning even when stats are missing (e.g when threshold is set to <=1).
When stats are missing and threshold is >1, we should fallback to not use preferred partitioning (previous default).

Copy link
Copy Markdown
Member

@sopel39 sopel39 Feb 25, 2021

Choose a reason for hiding this comment

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

we should also enable use-preferred-write-partitioning by default (separate commit).
Maybe we should also rename that property to use-automatic-preferred-write-partitioning and mark the old one as legacy since the previous behavior is changing. wdyt @findepi ?

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from 3246266 to 3f150ee Compare March 1, 2021 11:03
@skrzypo987
Copy link
Copy Markdown
Member Author

Another version.
Handles no stats/nan case gracefully. See TestPreferWritePartitioning for a list of cases.
Docs updated, however waiting for #7043 to be finally polished.
There is, however, a problem with naming - min number of partitions implies < logic, but it actually is <=. At this point we can use < since 0 is explicitly handled and keep the min in the name.
@sopel39

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.

follow up PR. I would like @mosabua to review it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe a follow-up commit? Features and docs should IMO be added atomically.

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.

if the number of partitions cannot be estimated or preferred-write-partitioning-min-number-of-partitions > 1 then preferred write partitioning won't be used. Setting preferred-write-partitioning-min-number-of-partitions to value less or equal to 1 will force Trino to use preferrered write partitioning

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

or preferred-write-partitioning-min-number-of-partitions > 1 then preferred write partitioning won't be used means that setting this value > 1 will always disable the feature. And this is not the case.
Let's wait for @mosabua to comment on that.

@sopel39
Copy link
Copy Markdown
Member

sopel39 commented Mar 1, 2021

There is, however, a problem with naming - min number of partitions implies < logic, but it actually is <=. At this point we can use < since 0 is explicitly handled and keep the min in the name.

I understand it that if estimated number of partitions >= min threshold, we use preferred write partitioning.

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from 3f150ee to cc07a51 Compare March 1, 2021 12:22
@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from cc07a51 to ba2906a Compare March 1, 2021 15:00
Copy link
Copy Markdown
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

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

lgtm % comments

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.

testCreateTableAsSelectUnpartitioned should use withPreferredPartitioning. Please extract as a separate commit

@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from ba2906a to 8cccfac Compare March 2, 2021 09:05
Copy link
Copy Markdown
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

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

lgtm % comment about rule placing, let's enable preferred partitioning by default

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.

Move it before or after reorder joins is applied. The assumption is that for reorder joins we should have the most accurate stats:

  • PredicatePushDown has been run with useTableProperties
  • later in the planning exchange nodes are added which might confuse stats.

Please add a comment why there.

Make 'CreateTableAsSelectUnpartitioned' test use preferred partitioning
Copy link
Copy Markdown
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

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

small comment

skrzypo987 added 3 commits March 2, 2021 15:53
Trino will enable preferred write partitioning only when estimated
number of partitions is lower than preferred_write_partitioning_min_number_of_partitions
@skrzypo987 skrzypo987 force-pushed the skrzypo/019-preferred-writes-threshold branch from c787f46 to 65db157 Compare March 2, 2021 14:55

// Prefer write partitioning rule requires accurate stats.
// Therefore PredicatePushDown, columnPruningOptimizer and
// RemoveRedundantIdentityProjections need to run beforehand.
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.

nit: we could remove RemoveRedundantIdentityProjections from both comments (here and below) as it should not affect stats. This could be separate PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll handle it when I get some free cycles

@sopel39 sopel39 merged commit a5cbc5c into trinodb:master Mar 8, 2021
@sopel39 sopel39 mentioned this pull request Mar 8, 2021
10 tasks
@martint martint added this to the 354 milestone Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants