Skip to content

Schema-qualified column references don't work correctly with tables that have the same name in different schemas #24667

@tuantran0910

Description

@tuantran0910

Describe the bug

When I have two tables with the same name in different schemas (e.g., public.users and public_staging.users), using fully-qualified column names like public_staging.users.id doesn't correctly distinguish between the two tables in EXISTS subqueries.

Error message/log


To Reproduce

-- Step 1: Create schemas
CREATE SCHEMA IF NOT EXISTS public_staging;

-- Step 2: Create first table in public schema
CREATE TABLE public.users (
    id INT PRIMARY KEY,
    name TEXT,
    is_active BOOLEAN
);

INSERT INTO public.users (id, name, is_active) VALUES
    (1, 'Alice', true),
    (2, 'Bob', false),
    (3, 'Charlie', false);

-- Step 3: Create second table with same name in different schema
CREATE TABLE public_staging.users AS
SELECT * FROM public.users WHERE is_active = false;

-- Verify: public_staging.users has 2 rows (Bob and Charlie)
SELECT * FROM public_staging.users;

-- Step 4: Query with EXISTS using fully-qualified column names
-- This SHOULD return 2 rows (Bob and Charlie who exist in both tables)
-- But it may return wrong results due to the bug
SELECT *
FROM public.users
WHERE EXISTS (
    SELECT 1
    FROM public_staging.users
    WHERE public_staging.users.id = public.users.id
    AND public_staging.users.is_active = false
);

The result after running the last query is:

 id |  name   | is_active
----+---------+-----------
  1 | Alice   | t
  2 | Bob     | f
  3 | Charlie | f

Expected behavior

The expected result should be 2 rows (id=2 Bob, id=3 Charlie) and not (id=1 Alice) as query contains condition is_active = false.

 id |  name   | is_active
----+---------+-----------
  2 | Bob     | f
  3 | Charlie | f

How did you deploy RisingWave?

The official Risingwave Docker Compose file.

The version of RisingWave

dev=> select version();
                                    version
--------------------------------------------------------------------------------
 PostgreSQL 13.14.0-RisingWave-2.7.2 (30301dc965a6f30c08de859e2be0e6cb1b66f6b0)
(1 row)
➜ docker image ls | grep risingwave
risingwavelabs/risingwave                    v2.7.2                  70e134006f14   12 days ago     7.46GB

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugType: Bug. Only for issues.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions