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

fix(sink): derive append only from optimizer when no format declared #14065

Closed
wants to merge 8 commits into from

Conversation

st1page
Copy link
Contributor

@st1page st1page commented Dec 19, 2023

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

What's changed and what's your intention?

  • Add a branch for the case that the user does not declare sink type/sink format,
  • allow force append only when there is no FORMAT clause

which is especially useful for "CREATE SINK INTO TABLE"

create table t(a int) append only;
create table tt(a int) append only;
create table ttt(a int);

dev=> 
explain create sink s into t as select a from tt;
                             QUERY PLAN                              
---------------------------------------------------------------------
 StreamProject { exprs: [tt.a, null:Serial] }
 └─StreamSink { type: AppendOnly, columns: [a, tt._row_id(hidden)] }
   └─StreamTableScan { table: tt, columns: [a, _row_id] }
(3 rows)

dev=> 
explain create sink s into t as select a from ttt with (force_append_only = true);
                                QUERY PLAN                                 
---------------------------------------------------------------------------
 StreamProject { exprs: [ttt.a, null:Serial] }
 └─StreamSink { type: ForceAppendOnly, columns: [a, ttt._row_id(hidden)] }
   └─StreamTableScan { table: ttt, columns: [a, _row_id] }
(3 rows)

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@github-actions github-actions bot added the type/fix Bug fix label Dec 19, 2023
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (ef6d483) 68.10% compared to head (89922a6) 68.10%.
Report is 30 commits behind head on main.

Files Patch % Lines
...rc/frontend/src/optimizer/plan_node/stream_sink.rs 69.23% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14065      +/-   ##
==========================================
- Coverage   68.10%   68.10%   -0.01%     
==========================================
  Files        1543     1543              
  Lines      267107   267111       +4     
==========================================
+ Hits       181915   181917       +2     
- Misses      85192    85194       +2     
Flag Coverage Δ
rust 68.10% <69.23%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

Code itself lgtm as long as all the behavior changes are intentional. Please confirm before merge.

(false, true, true) => Ok(SinkType::ForceAppendOnly),
(_, false, false) => Ok(SinkType::Upsert),
(false, true, false) => {
(true, DefinedAppendOnly|NotDefined, _) => Ok(SinkType::AppendOnly),
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking, this is a backward incompatible change: NotDefined was considered false before this PR, even when frontend derives it is actually append only. It used to return SinkType::Upsert in this case. This may or may not be a real problem.

One such example:
https://github.com/risingwavelabs/risingwave/blob/main/integration_tests/elasticsearch-sink/create_sink.sql

To list all behavior changes:

frontend derived user defined user force old new
true undefined true err cannot force SinkType::AppendOnly
true undefined false SinkType::Upsert SinkType::AppendOnly
false undefined true err cannot force SinkType::ForceAppendOnly
false undefined false SinkType::Upsert SinkType::Upsert (no change)

Based on our previous discussion, we wanted to make format required if backward compatibility was not a concern. This PR is actually making the backward compatibility promise harder to maintain, as undefined can now mean AppendOnly/ForceAppendOnly/Upsert in different cases, which used to be always Upsert. cc @tabVersion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your clarification. If we do not maintain the compatibility for those errored statements, the only change is this one.

this is a backward incompatible change: NotDefined was considered false before this PR, even when frontend derives it is actually append only.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do not maintain the compatibility for those errored statements

In my opinion, it is okay now to move from err to non-err in this PR. However, if we want to move from non-err to err again in the future, it would be a breaking change. This is what I mean by making the backward compatibility promise harder to maintain.

@st1page
Copy link
Contributor Author

st1page commented Dec 21, 2023

After offline, it will be implemented with a less invasive method

@st1page st1page closed this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants