Skip to content

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

Closed

Description

@avamingli

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

Activity

  1. self-assigned this
    on Dec 22, 2023
  2. avamingli commented on Dec 22, 2023

    @avamingli
    ContributorAuthor

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

  3. avamingli commented on Dec 25, 2023

    @avamingli
    ContributorAuthor

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

  4. avamingli commented on Dec 26, 2023

    @avamingli
    ContributorAuthor

    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().

  5. avamingli commented on Dec 29, 2023

    @avamingli
    ContributorAuthor

    Fixed in #348

  6. added a commit that references this issue on Jan 26, 2026
  7. added a commit that references this issue on Mar 10, 2026
  8. added a commit that references this issue on Mar 12, 2026
  9. added a commit that references this issue on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: BugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions