Skip to content

Conversation

@chenzl25
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Previously, index's stream key is the same as the primary key of the primary table, but the distribution keys of the index are the index columns. In streaming queries, it is important to include the distribution keys to the stream keys, so in this PR, we will add the distribution keys of indexes to the stream keys. And for the backward compatibility issue, we add a method stream_key() to the table catalog, so that we can always include the distribution keys to the stream keys. We should never use the stream_key field directly, instead we should use the stream_key() method in the future.

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • I have checked the Release Timeline and Currently Supported Versions to determine which release branches I need to cherry-pick this PR into.

Documentation

  • My PR needs documentation updates.
Release note

@github-actions github-actions bot added the type/fix Type: Bug fix. Only for pull requests. label Oct 28, 2025
@BugenZhao BugenZhao changed the title fix(streaming): fix index's stream key fix(streaming): fix index's stream key to include distribution key Oct 28, 2025
Comment on lines -221 to -222
.map(|index| i2o.try_map(index))
.collect::<Option<Vec<_>>>()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The derivation of join keys logic is changed. We apply the i2o mapping at the end. Otherwise, index selection for streaming join might panic, because index selection will replace a primary table with an index. Before this PR, they will have the same stream keys, but after this PR, they have different stream keys. For other operator like Agg, TopN, we can safely replace it with indexes, because the index stream_key's existence can always be guaranteed after logical_rewrite_for_stream. However, for the join, we only keep one side of the join key as the join's stream_key, and the other side's join key could be removed (even if it is the stream_key of the index).

@chenzl25
Copy link
Contributor Author

thread 'rw-streaming' (19144930) panicked at src/stream/src/executor/wrapper/update_check.rs:38:21:
assertion left == right failed: U- and U+ should have same stream key
U- row: [8852, 107730, 1, 5, 773, NULL]
U- key: [8852, 1, 5, 773, NULL]
U+ row: [6892, 107730, 1, 5, 773, NULL]
U+ key: [6892, 1, 5, 773, NULL]
stream key indices: [0, 2, 3, 4, 5]
executor: Materialize 13D00000003
left: Project { row: [Some(Decimal(Normalized(8852))), Some(Int32(107730)), Some(Int32(1)), Some(Int32(5)), Some(Int32(773)), None], indices: [0, 2, 3, 4, 5] }
right: Project { row: [Some(Decimal(Normalized(6892))), Some(Int32(107730)), Some(Int32(1)), Some(Int32(5)), Some(Int32(773)), None], indices: [0, 2, 3, 4, 5] }

The e2e test failed, because it is possible that ExchangeExecutor passes through the U-/U+ to a same actor if the vnode of the distribution key calculation is the same even though the distribution key is changed. But Exchange's distribution key should be part of the stream key of the downstream executor.

It means we need to change U-/U+ to D-/I+ in ExchangeExecutor when the columns of distribution key are changed instead of doing these changes when vnode are different.

@chenzl25
Copy link
Contributor Author

chenzl25 commented Oct 29, 2025

thread 'rw-streaming' (19144930) panicked at src/stream/src/executor/wrapper/update_check.rs:38:21:
assertion left == right failed: U- and U+ should have same stream key
U- row: [8852, 107730, 1, 5, 773, NULL]
U- key: [8852, 1, 5, 773, NULL]
U+ row: [6892, 107730, 1, 5, 773, NULL]
U+ key: [6892, 1, 5, 773, NULL]
stream key indices: [0, 2, 3, 4, 5]
executor: Materialize 13D00000003
left: Project { row: [Some(Decimal(Normalized(8852))), Some(Int32(107730)), Some(Int32(1)), Some(Int32(5)), Some(Int32(773)), None], indices: [0, 2, 3, 4, 5] }
right: Project { row: [Some(Decimal(Normalized(6892))), Some(Int32(107730)), Some(Int32(1)), Some(Int32(5)), Some(Int32(773)), None], indices: [0, 2, 3, 4, 5] }

The e2e test failed, because it is possible that ExchangeExecutor passes through the U-/U+ to a same actor if the vnode of the distribution key calculation is the same even though the distribution key is changed. But Exchange's distribution key should be part of the stream key of the downstream executor.

It means we need to change U-/U+ to D-/I+ in ExchangeExecutor when the columns of distribution key are changed instead of doing these changes when vnode are different.

waiting for #23603

@chenzl25 chenzl25 requested a review from BugenZhao October 30, 2025 06:53
@BugenZhao BugenZhao force-pushed the dylan/fix_index_stream_key branch from 6f66aef to 9629294 Compare October 30, 2025 08:30
Copy link
Member

BugenZhao commented Oct 30, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM!

@chenzl25 chenzl25 enabled auto-merge October 30, 2025 08:56
@chenzl25 chenzl25 added this pull request to the merge queue Oct 30, 2025
@chenzl25 chenzl25 removed this pull request from the merge queue due to a manual request Oct 30, 2025
@chenzl25 chenzl25 added this pull request to the merge queue Oct 31, 2025
Merged via the queue into main with commit 63fd8af Oct 31, 2025
33 of 35 checks passed
@chenzl25 chenzl25 deleted the dylan/fix_index_stream_key branch October 31, 2025 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/fix Type: Bug fix. Only for pull requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants