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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1009,6 +1010,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;
Expand Down Expand Up @@ -2621,6 +2625,10 @@ public int getWaitTimeoutS() {
return waitTimeout;
}

public boolean isEnableCompareForNull() {
return 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();
+    }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6155,7 +6155,12 @@ public ParseNode visitComparison(StarRocksParser.ComparisonContext context) {
private static BinaryType getComparisonOperator(Token symbol) {
switch (symbol.getType()) {
case StarRocksParser.EQ:
return BinaryType.EQ;
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable() != null
&& ConnectContext.get().getSessionVariable().isEnableCompareForNull()) {
return BinaryType.EQ_FOR_NULL;
} else {
return BinaryType.EQ;
}
case StarRocksParser.NEQ:
return BinaryType.NE;
case StarRocksParser.LT:
Expand Down
Loading