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

[Bug] [AQUMV]ERROR: invalid attnum 3 for relation "aqumv_t2" (ruleutils.c:7260) #344

Closed
2 tasks done
avamingli opened this issue Dec 22, 2023 · 4 comments
Closed
2 tasks done
Assignees
Labels
type: Bug Something isn't working

Comments

@avamingli
Copy link
Collaborator

Cloudberry Database version

@ a70f7ee

What happened

When compute AGG on views, an error of invalid attnum occured.

What you think should happen instead

No response

How to reproduce

begin;
create table aqumv_t2(c1 int, c2 int, c3 int) distributed by (c1);
insert into aqumv_t2 select i, i+1, i+2 from generate_series(1, 100) i;
insert into aqumv_t2 values (91, NULL, 95);
analyze aqumv_t2;
create incremental materialized view aqumv_mvt2_1 as
  select c3 as mc3, c1 as mc1
  from aqumv_t2 where c1 > 90;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'mc1' as the Cloudberry Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
analyze aqumv_mvt2_1;
set local enable_answer_query_using_materialized_views = off;
explain(costs off, verbose)
select count(c3) from aqumv_t2 where c1 > 90;
                                    QUERY PLAN                                     
-----------------------------------------------------------------------------------
 Finalize Aggregate
   Output: count(c3)
   ->  Gather Motion 3:1  (slice1; segments: 3)
         Output: (PARTIAL count(c3))
         ->  Partial Aggregate
               Output: PARTIAL count(c3)
               ->  Seq Scan on public.aqumv_t2
                     Output: c1, c2, c3
                     Filter: (aqumv_t2.c1 > 90)
 Settings: enable_answer_query_using_materialized_views = 'off', optimizer = 'off'
 Optimizer: Postgres query optimizer
(11 rows)

select count(c3) from aqumv_t2 where c1 > 90;
 count 
-------
    11
(1 row)

set local enable_answer_query_using_materialized_views = on;
explain(costs off, verbose)
select count(c3) from aqumv_t2 where c1 > 90;
ERROR:  invalid attnum 3 for relation "aqumv_t2" (ruleutils.c:7260)
select count(c3) from aqumv_t2 where c1 > 90;
ERROR:  current transaction is aborted, commands ignored until end of transaction block
abort;

Operating System

Ubuntu 22.04.2 LTS

Anything else

No response

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

@avamingli avamingli added the type: Bug Something isn't working label Dec 22, 2023
@avamingli avamingli self-assigned this Dec 22, 2023
@avamingli
Copy link
Collaborator Author

avamingli commented Dec 22, 2023

It seems related to disorder of column, but the error shows it's on origin table which is confused after rewritten.
Working on this.

@avamingli
Copy link
Collaborator Author

Update: make sure this has nothing to do with TupleDesc, need dig more.

@avamingli
Copy link
Collaborator Author

The root cause is PlannerInfo's stuff need to be refilled after rewritten.
They may be used to fetch rels after planner, for example: use physical rel's target list in create_plan().

@avamingli
Copy link
Collaborator Author

Fixed in #348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant