Repository navigation
Add configurable table-backed view definitions - #72
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1672c3db9c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| auto definition = definitions.Find(GetName(drop)); | ||
| if (definition) { | ||
| return BindDefinitionWrite(context, parent, | ||
| "DELETE FROM " + table + " WHERE " + KeyPredicate(definition->name)); |
There was a problem hiding this comment.
Respect temporary-view shadowing before deleting stored definitions
When a temporary native view shadows a stored permanent view with the same name, an unqualified DROP VIEW finds the permanent definition here and deletes its row instead of dropping the temporary view. For example, creating stored v, then CREATE TEMP VIEW v AS SELECT 1, then DROP VIEW v destroys the persistent definition while leaving the temporary view intact. Resolve the native target and its precedence before choosing the definition-table DELETE, consistent with the native-entry check already used by YardstickStoredRelationName.
Useful? React with 👍 / 👎.
| visit_ref = [&](TableRef &ref) { | ||
| if (ref.type != TableReferenceType::BASE_TABLE || !ref.query_location.IsValid()) return; | ||
| auto input = GetName(ref.Cast<BaseTableRef>()); | ||
| if (input.catalog.empty() && input.schema.empty() && cte_names.count(StringUtil::Lower(input.name))) return; |
There was a problem hiding this comment.
Track CTE names within their lexical scope when qualifying sources
If a nested subquery declares a CTE named sales, the query-wide cte_names set also exempts an unrelated outer FROM sales from qualification. A declaration such as SELECT SUM(amount) AS MEASURE total FROM sales WHERE EXISTS (WITH sales AS (SELECT 1) SELECT * FROM sales) therefore saves the outer source unqualified. After a later session changes its schema/search path, that stored measure can silently read a different sales table, contrary to the source-binding guarantee. Track visible CTEs per query scope rather than excluding every occurrence of any collected CTE name.
Useful? React with 👍 / 👎.
| auto sql = existing | ||
| ? "UPDATE " + table + " SET definition_sql = " + QuoteString(definition_sql) + " WHERE " + KeyPredicate(name) | ||
| : "INSERT INTO " + table + " (view_catalog, view_schema, view_name, definition_sql) VALUES (" + | ||
| QuoteString(name.catalog) + ", " + QuoteString(name.schema) + ", " + QuoteString(name.name) + ", " + QuoteString(definition_sql) + ")"; |
There was a problem hiding this comment.
Enforce definition-key uniqueness across concurrent creates
With an initialized definitions table, two sessions can concurrently create the same previously absent view: both binding-time lookups see no existing definition, and both unconstrained INSERTs can commit. The automatically created table has no unique constraint on the definition key, so the next semantic lookup encounters duplicate rows and DefinitionScope throws, preventing queries against otherwise unrelated stored views as well. Enforce case-insensitive key uniqueness atomically, or otherwise serialize conflicting creates; the snapshot existence check alone does not protect the store.
Useful? React with 👍 / 👎.
Yardstick measure definitions currently live in process memory, so reopening a database does not recover their semantics. Add the session setting
yardstick_definition_tableto store definitions in a fully qualified regular table in a writable DuckDB attachment:The selected table is the sole source of truth. CREATE, IF NOT EXISTS, semantic or plain REPLACE, and DROP use ordinary table operations in the caller's transaction. Later sessions resolve definitions automatically after selecting the same store, without duplicate native views or export/import calls. An unset setting preserves existing behavior;
temp.main.yardstick_viewssupports session-local storage.Definition mutations acquire and verify a reserved guard row in the same table before writing, rejecting conflicting or stale writers without requiring backend UNIQUE constraints. New tables initialize the guard atomically. Existing guard-free tables remain readable and provide one-time initialization instructions requiring exclusive writer access. Direct external table edits bypass this protocol.
Query-local namespaces isolate stores and sessions. Lookup and DROP respect temporary native views; saved sources retain lexical CTE visibility and qualified catalog/schema names. Prepared queries rebind after replacements. Simple native-table queries skip definition scans; semantic lookups use DuckDB and attachment caching without a separate TTL cache. Includes native and legacy binder integration and usage documentation.
Validation:
PostgreSQL and Iceberg connectors were not directly exercised. The selected attachment must provide transactional table reads/writes and reject conflicting updates; all participating definition writers must use the guard protocol.