Skip to content

Conversation

kryonix
Copy link
Contributor

@kryonix kryonix commented Mar 31, 2025

This PR fixes a bug found in the nightly CI tests:

WITH RECURSIVE tbl(a, b) USING KEY (a) AS MATERIALIZED (
  SELECT 5, 1
    UNION
  SELECT a, b + 1
  FROM tbl WHERE b < a),
tbl1(a,b) AS (SELECT * FROM recurring.tbl)
SELECT * FROM tbl1;

The CTE tbl1 should not be able to reference recurring.tbl, the Binder should detect that and throw an appropriate error. This, however, did not work as expected when the USING KEY CTE was MATERIALIZED. Then, a shared_pointer dereferenced to NULL. This is now fixed.

This PR fixes a bug found in the nightly CI tests:
```sql
WITH RECURSIVE tbl(a, b) USING KEY (a) AS MATERIALIZED (
  SELECT 5, 1
    UNION
  SELECT a, b + 1
  FROM tbl WHERE b < a),
tbl1(a,b) AS (SELECT * FROM recurring.tbl)
SELECT * FROM tbl1;
```

The CTE `tbl1` should not be able to reference `recurring.tbl`, the
Binder should detect that and throw an appropriate error. This, however,
did not work as expected when the `USING KEY` CTE was `MATERIALIZED`.
Then, a `shared_pointer` dereferenced to NULL. This is now fixed.
@Mytherin Mytherin merged commit daf2fa3 into duckdb:main Mar 31, 2025
42 of 47 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Fix USING KEY reference error (duckdb/duckdb#16906)
Adding gzip version of shell for linux/osx install script (duckdb/duckdb#16116)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Fix USING KEY reference error (duckdb/duckdb#16906)
Adding gzip version of shell for linux/osx install script (duckdb/duckdb#16116)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 16, 2025
Fix USING KEY reference error (duckdb/duckdb#16906)
Adding gzip version of shell for linux/osx install script (duckdb/duckdb#16116)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 16, 2025
Fix USING KEY reference error (duckdb/duckdb#16906)
Adding gzip version of shell for linux/osx install script (duckdb/duckdb#16116)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 17, 2025
Fix USING KEY reference error (duckdb/duckdb#16906)
Adding gzip version of shell for linux/osx install script (duckdb/duckdb#16116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants