Xiao-zhen-Liu commented on code in PR #5967:
URL: https://github.com/apache/texera/pull/5967#discussion_r3493440286


##########
sql/updates/26.sql:
##########
@@ -0,0 +1,47 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- ============================================
+-- 1. Connect to the texera_db database
+-- ============================================
+\c texera_db
+
+SET search_path TO texera_db;
+
+-- ============================================
+-- 2. Add the operator_port_cache table
+-- ============================================
+BEGIN;
+
+-- Caches a materialized output port result across executions, keyed by the 
cache
+-- key (a SHA-256 hash of the upstream sub-DAG). cache_key_json holds the JSON
+-- the cache key is computed from.
+CREATE TABLE IF NOT EXISTS operator_port_cache
+(
+    workflow_id         INT NOT NULL,
+    global_port_id      VARCHAR(200) NOT NULL,
+    cache_key           CHAR(64) NOT NULL,
+    cache_key_json      TEXT NOT NULL,

Review Comment:
   Two columns on purpose: `cache_key` is the SHA-256 hash we look up by (and 
part of the PK), and `cache_key_json` is the JSON it was computed from. On a 
hash hit we compare the stored JSON to confirm the match, so a hash collision 
can never reuse the wrong result.



##########
sql/updates/26.sql:
##########
@@ -0,0 +1,47 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- ============================================
+-- 1. Connect to the texera_db database
+-- ============================================
+\c texera_db
+
+SET search_path TO texera_db;
+
+-- ============================================
+-- 2. Add the operator_port_cache table
+-- ============================================
+BEGIN;
+
+-- Caches a materialized output port result across executions, keyed by the 
cache
+-- key (a SHA-256 hash of the upstream sub-DAG). cache_key_json holds the JSON
+-- the cache key is computed from.
+CREATE TABLE IF NOT EXISTS operator_port_cache
+(
+    workflow_id         INT NOT NULL,
+    global_port_id      VARCHAR(200) NOT NULL,
+    cache_key           CHAR(64) NOT NULL,
+    cache_key_json      TEXT NOT NULL,
+    result_uri          TEXT NOT NULL,

Review Comment:
   Done, renamed to `storage_uri`.



##########
sql/updates/26.sql:
##########
@@ -0,0 +1,47 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements.  See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership.  The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License.  You may obtain a copy of the License at
+--
+--   http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied.  See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+-- ============================================
+-- 1. Connect to the texera_db database
+-- ============================================
+\c texera_db
+
+SET search_path TO texera_db;
+
+-- ============================================
+-- 2. Add the operator_port_cache table
+-- ============================================
+BEGIN;
+
+-- Caches a materialized output port result across executions, keyed by the 
cache
+-- key (a SHA-256 hash of the upstream sub-DAG). cache_key_json holds the JSON
+-- the cache key is computed from.
+CREATE TABLE IF NOT EXISTS operator_port_cache
+(
+    workflow_id         INT NOT NULL,
+    global_port_id      VARCHAR(200) NOT NULL,
+    cache_key           CHAR(64) NOT NULL,
+    cache_key_json      TEXT NOT NULL,
+    result_uri          TEXT NOT NULL,
+    tuple_count         BIGINT,

Review Comment:
   I'd keep `tuple_count`. A cache row is immutable (a changed computation is a 
new row, never an update), so it can't drift from the Iceberg result. It's 
populated at materialization and read by the coordinator during execution — the 
coordinator already queries this table for the cache lookup, so a cached 
region's output stats come from the same row with no extra read. Reading it 
from `getCount()` instead is a catalog/storage round-trip per cached port on 
the coordinator, which is the work the cache is meant to avoid.



##########
sql/texera_ddl.sql:
##########
@@ -371,6 +372,24 @@ CREATE TABLE operator_port_executions
     FOREIGN KEY (workflow_execution_id) REFERENCES workflow_executions(eid) ON 
DELETE CASCADE
 );
 
+-- operator_port_cache
+-- Caches a materialized output port result across executions, keyed by the 
cache
+-- key (a SHA-256 hash of the upstream sub-DAG). cache_key_json holds the JSON
+-- the cache key is computed from.
+CREATE TABLE operator_port_cache
+(
+    workflow_id         INT NOT NULL,
+    global_port_id      VARCHAR(200) NOT NULL,
+    cache_key           CHAR(64) NOT NULL,
+    cache_key_json      TEXT NOT NULL,
+    result_uri          TEXT NOT NULL,
+    tuple_count         BIGINT,
+    source_execution_id BIGINT,
+    updated_at          TIMESTAMPTZ NOT NULL DEFAULT now(),
+    PRIMARY KEY (workflow_id, global_port_id, cache_key),

Review Comment:
   Intentional — the cache is reused across executions, keyed by `cache_key` 
(the upstream computation hash). Putting `execution_id` in the PK would create 
a row per execution and prevent reuse. `source_execution_id` is provenance 
metadata. The per-execution tables key by execution because they store 
per-execution results — a different concern.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to