BUG #16909: On update (not insert) the attisdropped flag is set for tables which are recreated with the same col

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: grumpylittleted(at)googlemail(dot)com
Subject: BUG #16909: On update (not insert) the attisdropped flag is set for tables which are recreated with the same col
Date: 2021-03-02 10:34:55
Message-ID: 16909-3a6da1ab19f5652b@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16909
Logged by: Grumpylittleted
Email address: grumpylittleted(at)googlemail(dot)com
PostgreSQL version: 13.2
Operating system: Linux 5.8.0-44-generic #50~20.04.1-Ubuntu S
Description:

/*

BUG:

Using 13.2
On update (not insert) the attisdropped flag is set for tables which are
recreated with the same column names as the original but where preceding
columns have been dropped

METHOD:
Create a table t with more than two columns: x, y, z
Drop that table
Create a table t with a subset of the columns with the same name as the
previous table: here we remove y
Insert a new row: there are two attributes (correct), neither of which
have the attisdropped flag set (correct) (so bug not apparent with
inserts)
Update the row: there are two attributes (correct), the first attribute
has the attisdropped flag unset (correct) BUT the second attribute has the
attisdropped flag set (incorrect)

make
sudo cp ./f.so `pg_config --pkglibdir`

SQL:

create or replace function f() returns trigger as './f.so','f' language c
strict;

drop table if exists t cascade;
create table t(x int, y int, z int);

drop table t cascade;
create table t(x int, z int);
create trigger tf before insert or update on t for each row execute
procedure f();
insert into t values(4,5); -- attr num=1 attisdropped=0
update t set x=2;

*/

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
#include "commands/trigger.h"
#include "utils/rel.h"
#include "utils/fmgrprotos.h"

PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1( f );
Datum f( PG_FUNCTION_ARGS ) {

TriggerData *trigdata = ( TriggerData * ) fcinfo->context;
const TupleDesc tupdesc = trigdata->tg_relation->rd_att;
HeapTuple tuple = TRIGGER_FIRED_BY_UPDATE( trigdata->tg_event ) ?
trigdata->tg_newtuple : trigdata->tg_trigtuple;

for( int i = 1; i <= tupdesc->natts; i++ ) {
elog( INFO, "attr num=%d attisdropped=%d", i, TupleDescAttr( tupdesc, i
)->attisdropped );
}

return PointerGetDatum( tuple );

}

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Steele 2021-03-02 12:46:21 Re: BUG #16894: PANIC: WAL contains references to invalid pages
Previous Message hubert depesz lubaczewski 2021-03-02 09:00:39 Re: ORDER BY DESC / ASC