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

[Enhancement]Add session variable enable_compare_for_null to support compare null … #51201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

even986025158
Copy link
Contributor

@even986025158 even986025158 commented Sep 20, 2024

…when use =
need use = to compare null = null and want to it return true

Why I'm doing:

Some services migrated from other systems want to use = for null comparison, but do not want to modify the SQL

What I'm doing:

add the session variable enable_compare_for_null to support compare null with =
Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
  • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@even986025158 even986025158 requested a review from a team as a code owner September 20, 2024 06:18
public void setEnableCompareForNull(boolean enableCompareForNull) {
this.enableCompareForNull = enableCompareForNull;
}

public long getSqlMode() {
return sqlMode;
}
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Serialization inconsistency due to missing enableCompareForNull field.

You can modify the code like this:

    @@ -173,6 +173,7 @@ public class SessionVariable implements Serializable, Writable, Cloneable {
     public static final String QUERY_CACHE_TYPE = "query_cache_type";
     public static final String INTERACTIVE_TIMEOUT = "interactive_timeout";
     public static final String WAIT_TIMEOUT = "wait_timeout";
+    public static final String ENABLE_COMPARE_FOR_NULL = "enable_compare_for_null";
 
     public static final String CATALOG = "catalog";
     public static final String NET_WRITE_TIMEOUT = "net_write_timeout";
@@ -1005,6 +1006,9 @@ public static MaterializedViewRewriteMode parse(String str) {
     @VariableMgr.VarAttr(name = WAIT_TIMEOUT)
     private int waitTimeout = 28800;
 
+    @VariableMgr.VarAttr(name = ENABLE_COMPARE_FOR_NULL)
+    private boolean enableCompareForNull = false;
+
     // The number of seconds to wait for a block to be written to a connection before aborting the write
     @VariableMgr.VarAttr(name = NET_WRITE_TIMEOUT)
     private int netWriteTimeout = 60;
@@ -2610,6 +2614,14 @@ public int getWaitTimeoutS() {
         return waitTimeout;
     }
 
+    public boolean isEnableCompareForNull() {
+        return enableCompareForNull;
+    }
+
+    public void setEnableCompareForNull(boolean enableCompareForNull) {
+        this.enableCompareForNull = enableCompareForNull;
+    }
+
     public long getSqlMode() {
         return sqlMode;
     }

+    /**
+     * Ensure that enableCompareForNull is serialized correctly.
+     */
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeBoolean(enableCompareForNull);
+    }
+
+    /**
+     * Ensure that enableCompareForNull is deserialized correctly.
+     */
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        enableCompareForNull = in.readBoolean();
+    }

@even986025158 even986025158 changed the title Add session variable enable_compare_for_null to support compare null … [Enhancement]Add session variable enable_compare_for_null to support compare null … Sep 20, 2024
@even986025158 even986025158 force-pushed the community/enable_compare_for_null branch from 00e2bb5 to 2ec28e2 Compare September 23, 2024 11:46
@trueeyu
Copy link
Contributor

trueeyu commented Sep 25, 2024

@Mergifyio rebase main

…when use =

Signed-off-by: evenhuang <986025158@qq.com>
Copy link
Contributor

mergify bot commented Sep 25, 2024

rebase main

✅ Branch has been successfully rebased

@trueeyu trueeyu force-pushed the community/enable_compare_for_null branch from 2ec28e2 to 4342b98 Compare September 25, 2024 08:13
Copy link

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 2 / 2 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/qe/SessionVariable.java 2 2 100.00% []

@kangkaisen
Copy link
Collaborator

I think I should let the user modify the SQL rather than support this unreasonable behavior.

@even986025158
Copy link
Contributor Author

I think I should let the user modify the SQL rather than support this unreasonable behavior.

We actually hope that users can modify SQL, but due to some historical reasons, a large number of this type of SQL need to be modified. Users think that the workload is huge and there are certain risks in modification, so they hope that we support this feature. Moreover, for SR, supporting this parameter can meet more user scenarios, which is actually beneficial. In addition, it does not affect the original query by default. Users who need this feature can only enable it through parameters. If some users are unwilling to use SR because of this situation, I think this is actually a lose-lose result, so I think it is more reasonable to support this behavior through parameters.

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

Successfully merging this pull request may close these issues.

4 participants