Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Error [XX000]: ERROR: cache lookup failed for type 0 with pg auto explain #7596

Open
StepanYankevych opened this issue May 9, 2024 · 2 comments
Labels

Comments

@StepanYankevych
Copy link

pg 15.6 / 15.3
Citus 12.1.1 / 12.1.3
autoexplain ON

test case
CREATE TABLE billing.test_table
( report_id int8 NULL,
date_id int4 NOT NULL);

SELECT create_distributed_table('test_table', 'report_id');

CREATE OR REPLACE PROCEDURE billing.test_delete_from(p_date_id int)
LANGUAGE plpgsql AS
$body$

BEGIN
DELETE FROM billing.test_table
WHERE date_id = p_date_id;
END;
$body$;

CALL billing.test_delete_from(20240401);

SQL Error [XX000]: ERROR: cache lookup failed for type 0
Where: SQL statement "DELETE FROM billing.test_table
WHERE date_id = p_date_id"

PL/pgSQL function test_delete_from(integer) line 3 at SQL statement

BUT if we use constant instead of parameter then everything works fine

CREATE OR REPLACE PROCEDURE billing.test_delete_from(p_date_id int)
LANGUAGE plpgsql AS
$body$
BEGIN
DELETE FROM billing.test_table
WHERE date_id = 20240401;
END;
$body$;

Also using Function instead of procedure works fine.

Disabling auto_explain resolves the issue as well.
So looks like a bug: some incompatibility between Citus/autoexplain while
using delete inside procedure

The same bug was reported on the PostgreSQL mail list
https://www.postgresql.org/message-id/18458-61332181c54e5f5c%40postgresql.org

@emelsimsek emelsimsek added the bug label May 13, 2024
@emelsimsek
Copy link
Contributor

emelsimsek commented May 13, 2024

I debugged this a bit and it looks like a bug.

Repro Steps:

On the coordinator

CREATE TABLE billing.test_table
( report_id int8 NULL,
date_id int4 NOT NULL);

SELECT create_distributed_table('test_table', 'report_id');

CREATE OR REPLACE PROCEDURE billing.test_delete_from(p_date_id int)
LANGUAGE plpgsql AS
$$
BEGIN
DELETE FROM billing.test_table
WHERE date_id = p_date_id;
END;$$;


LOAD 'auto_explain';
SET auto_explain.log_min_duration = 0;
SET auto_explain.log_analyze to true;

CALL billing.test_delete_from(20240401);


Note that log_analyze being true or false produces different type of failures.

Below steps throws an error as well albeit a different on from reported.

CREATE TABLE billing.test_table
( report_id int8 NULL,
date_id int4 NOT NULL);

SELECT create_distributed_table('test_table', 'report_id');

CREATE OR REPLACE PROCEDURE billing.test_delete_from(p_date_id int)
LANGUAGE plpgsql AS
$$
BEGIN
DELETE FROM billing.test_table
WHERE date_id = p_date_id;
END;$$;


LOAD 'auto_explain';
SET auto_explain.log_min_duration = 0;
RESET auto_explain.log_analyze;

CALL billing.test_delete_from(20240401);


@emelsimsek
Copy link
Contributor

Created a PR #7598 for a possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants