You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "snazy (via GitHub)" <gi...@apache.org> on 2026/05/18 06:12:32 UTC

[PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

snazy opened a new pull request, #4474:
URL: https://github.com/apache/polaris/pull/4474

   Add a cheap serialized null probe for index values and use that in the public iterator path.
   
   The earlier iterator change (#4018) made lazy indexes deserialize every value just to skip tombstones, which was the wrong tradeoff for key-heavy scans. This keeps tombstone filtering without forcing full value materialization.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #4474:
URL: https://github.com/apache/polaris/pull/4474#discussion_r3286706564


##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -904,26 +909,43 @@ public IndexKey key() {
       return k;
     }
 
+    @Override
+    public boolean hasNonNullValue() {
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return false;
+      }
+      if (state != VALUE_STATE_UNMATERIALIZED) {
+        return true;
+      }
+      var nonNull =
+          !serializer.isNullSerialized(
+              serializedThreadSafe().limit(endOffset).position(valueOffset));
+      if (contentState == VALUE_STATE_UNMATERIALIZED) {
+        contentState = nonNull ? VALUE_STATE_NON_NULL : VALUE_STATE_NULL;
+      }
+      return nonNull;
+    }
+
     @Override
     @Nullable
     public V valueNullable() {
-      var c = content;
-      if (c == null) {
-        if (!hasContent) {
-          c =
-              content =
-                  serializer.deserialize(
-                      serializedThreadSafe().limit(endOffset).position(valueOffset));
-          hasContent = true;
-        }
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return null;
       }
+      if (state != VALUE_STATE_UNMATERIALIZED && state != VALUE_STATE_NON_NULL) {
+        return materializedContent(state);

Review Comment:
   Right, not necessary here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #4474:
URL: https://github.com/apache/polaris/pull/4474#discussion_r3286640203


##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -904,26 +909,43 @@ public IndexKey key() {
       return k;
     }
 
+    @Override
+    public boolean hasNonNullValue() {
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return false;
+      }
+      if (state != VALUE_STATE_UNMATERIALIZED) {
+        return true;
+      }
+      var nonNull =
+          !serializer.isNullSerialized(
+              serializedThreadSafe().limit(endOffset).position(valueOffset));
+      if (contentState == VALUE_STATE_UNMATERIALIZED) {
+        contentState = nonNull ? VALUE_STATE_NON_NULL : VALUE_STATE_NULL;

Review Comment:
   Went with a `AtomicReferenceFieldUpdater` to avoid an additional object instance and indirection.
   Had to make LazyIndexElement a static class for that, but that's not a runtime regression.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #4474:
URL: https://github.com/apache/polaris/pull/4474#discussion_r3283418656


##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/InternalIndexElement.java:
##########
@@ -47,5 +47,7 @@ interface InternalIndexElement<V> extends Index.Element<V> {
 
   int contentSerializedSize(IndexValueSerializer<V> ser);
 
+  boolean hasNonNullValue();

Review Comment:
   suggestion: `hasValue()` or `valuePresent()` (cf. `Optional.isPresent()`)



##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -802,10 +802,15 @@ private final class LazyIndexElement extends AbstractIndexElement<V> {
     /** The materialized key or {@code null}. */
     private IndexKey key;
 
-    /** The materialized content or {@code null}. */
-    private V content;
+    /**
+     * Holds either one of the {@code VALUE_STATE_*} sentinels or a materialized non-{@code null}
+     * content value.
+     */
+    private volatile Object contentState = VALUE_STATE_UNMATERIALIZED;
 
-    private boolean hasContent;
+    private static final Object VALUE_STATE_UNMATERIALIZED = new Object();
+    private static final Object VALUE_STATE_NULL = new Object();
+    private static final Object VALUE_STATE_NON_NULL = new Object();

Review Comment:
   suggestion: `VALUE_STATE_PRESENT`



##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -904,26 +909,43 @@ public IndexKey key() {
       return k;
     }
 
+    @Override
+    public boolean hasNonNullValue() {
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return false;
+      }
+      if (state != VALUE_STATE_UNMATERIALIZED) {
+        return true;
+      }
+      var nonNull =
+          !serializer.isNullSerialized(
+              serializedThreadSafe().limit(endOffset).position(valueOffset));
+      if (contentState == VALUE_STATE_UNMATERIALIZED) {

Review Comment:
   Do we really need this `if`? It does not prevent races WRT line 941, but adds confusion WRT line 918 🤔 



##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -904,26 +909,43 @@ public IndexKey key() {
       return k;
     }
 
+    @Override
+    public boolean hasNonNullValue() {
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return false;
+      }
+      if (state != VALUE_STATE_UNMATERIALIZED) {
+        return true;
+      }
+      var nonNull =
+          !serializer.isNullSerialized(
+              serializedThreadSafe().limit(endOffset).position(valueOffset));
+      if (contentState == VALUE_STATE_UNMATERIALIZED) {
+        contentState = nonNull ? VALUE_STATE_NON_NULL : VALUE_STATE_NULL;

Review Comment:
   WDYT about `AtomicReference.compareAndSet(VALUE_STATE_UNMATERIALIZED, nonNull ? VALUE_STATE_NON_NULL : VALUE_STATE_NULL)`?



##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -904,26 +909,43 @@ public IndexKey key() {
       return k;
     }
 
+    @Override
+    public boolean hasNonNullValue() {
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return false;
+      }
+      if (state != VALUE_STATE_UNMATERIALIZED) {
+        return true;
+      }
+      var nonNull =
+          !serializer.isNullSerialized(
+              serializedThreadSafe().limit(endOffset).position(valueOffset));
+      if (contentState == VALUE_STATE_UNMATERIALIZED) {
+        contentState = nonNull ? VALUE_STATE_NON_NULL : VALUE_STATE_NULL;
+      }
+      return nonNull;
+    }
+
     @Override
     @Nullable
     public V valueNullable() {
-      var c = content;
-      if (c == null) {
-        if (!hasContent) {
-          c =
-              content =
-                  serializer.deserialize(
-                      serializedThreadSafe().limit(endOffset).position(valueOffset));
-          hasContent = true;
-        }
+      var state = contentState;
+      if (state == VALUE_STATE_NULL) {
+        return null;
       }
+      if (state != VALUE_STATE_UNMATERIALIZED && state != VALUE_STATE_NON_NULL) {
+        return materializedContent(state);

Review Comment:
   the result of `materializedContent(state)` in this case is known to be `state`... why use this indirection? 🤔 



##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -943,6 +965,22 @@ public String toString() {
 
       return sb.toString();
     }
+
+    @Nullable
+    private V materializedContent() {
+      return materializedContent(contentState);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Nullable
+    private V materializedContent(Object state) {
+      if (state == VALUE_STATE_UNMATERIALIZED
+          || state == VALUE_STATE_NULL
+          || state == VALUE_STATE_NON_NULL) {
+        return null;

Review Comment:
   This actually returns something other that the materialized content (unless it's `null`) despite the method name 🤔 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #4474:
URL: https://github.com/apache/polaris/pull/4474#discussion_r3286703189


##########
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/indexes/IndexImpl.java:
##########
@@ -943,6 +965,22 @@ public String toString() {
 
       return sb.toString();
     }
+
+    @Nullable
+    private V materializedContent() {
+      return materializedContent(contentState);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Nullable
+    private V materializedContent(Object state) {
+      if (state == VALUE_STATE_UNMATERIALIZED
+          || state == VALUE_STATE_NULL
+          || state == VALUE_STATE_NON_NULL) {
+        return null;

Review Comment:
   True, renamed + added an `uncheckedCast` helper



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NoSQL: Avoid deserializing lazy NoSQL index tombstones [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy merged PR #4474:
URL: https://github.com/apache/polaris/pull/4474


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org