pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[Report Bug With Patch] Rel Cache Bug
4+ messages / 3 participants
[nested] [flat]

* [Report Bug With Patch] Rel Cache Bug
@ 2015-03-25 13:59 Jaimin Pan <jaimin.pan@gmail.com>
  2015-03-25 17:08 ` Re: [Report Bug With Patch] Rel Cache Bug Andres Freund <andres@2ndquadrant.com>
  2015-03-25 17:38 ` Re: [Report Bug With Patch] Rel Cache Bug Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 4+ messages in thread

From: Jaimin Pan @ 2015-03-25 13:59 UTC (permalink / raw)
  To: pgsql-bugs

Hi,

I think there is a bug in rel cache rebuild of release 9.4.1.
it also exists on some other release.

the issue was introduced by 491dd4a97daa6b4de9ee8401ada10ad5da76af46

-- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool rebuild)
                /* ... but actually, we don't have to update newrel->rd_rel
*/
                memcpy(relation->rd_rel, newrel->rd_rel, CLASS_TUPLE_SIZE);
                /* preserve old tupledesc and rules if no logical change */
-               if (keep_tupdesc)
+               if (!keep_tupdesc)
                        SWAPFIELD(TupleDesc, rd_att);
-               if (keep_rules)
+               if (!keep_rules)
                {
                        SWAPFIELD(RuleLock *, rd_rules);
                        SWAPFIELD(MemoryContext, rd_rulescxt);

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

bug.patch (application/octet-stream, 667B) download diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index f6520a0..733860c 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool rebuild) /* ... but actually, we don't have to update newrel->rd_rel */ memcpy(relation->rd_rel, newrel->rd_rel, CLASS_TUPLE_SIZE); /* preserve old tupledesc and rules if no logical change */ - if (keep_tupdesc) + if (!keep_tupdesc) SWAPFIELD(TupleDesc, rd_att); - if (keep_rules) + if (!keep_rules) { SWAPFIELD(RuleLock *, rd_rules); SWAPFIELD(MemoryContext, rd_rulescxt);
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: [Report Bug With Patch] Rel Cache Bug
  2015-03-25 13:59 [Report Bug With Patch] Rel Cache Bug Jaimin Pan <jaimin.pan@gmail.com>
@ 2015-03-25 17:08 ` Andres Freund <andres@2ndquadrant.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Andres Freund @ 2015-03-25 17:08 UTC (permalink / raw)
  To: Jaimin Pan <jaimin.pan@gmail.com>; +Cc: pgsql-bugs

Hi,

On 2015-03-25 21:59:17 +0800, Jaimin Pan wrote:
> I think there is a bug in rel cache rebuild of release 9.4.1.
> it also exists on some other release.
> 
> the issue was introduced by 491dd4a97daa6b4de9ee8401ada10ad5da76af46
> 
> -- a/src/backend/utils/cache/relcache.c
> +++ b/src/backend/utils/cache/relcache.c
> @@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool rebuild)
>                 /* ... but actually, we don't have to update newrel->rd_rel
> */
>                 memcpy(relation->rd_rel, newrel->rd_rel, CLASS_TUPLE_SIZE);
>                 /* preserve old tupledesc and rules if no logical change */
> -               if (keep_tupdesc)
> +               if (!keep_tupdesc)
>                         SWAPFIELD(TupleDesc, rd_att);
> -               if (keep_rules)
> +               if (!keep_rules)
>                 {
>                         SWAPFIELD(RuleLock *, rd_rules);
>                         SWAPFIELD(MemoryContext, rd_rulescxt);

> diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
> index f6520a0..733860c 100644
> --- a/src/backend/utils/cache/relcache.c
> +++ b/src/backend/utils/cache/relcache.c
> @@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool rebuild)
>  		/* ... but actually, we don't have to update newrel->rd_rel */
>  		memcpy(relation->rd_rel, newrel->rd_rel, CLASS_TUPLE_SIZE);
>  		/* preserve old tupledesc and rules if no logical change */
> -		if (keep_tupdesc)
> +		if (!keep_tupdesc)
>  			SWAPFIELD(TupleDesc, rd_att);
> -		if (keep_rules)
> +		if (!keep_rules)
>  		{
>  			SWAPFIELD(RuleLock *, rd_rules);
>  			SWAPFIELD(MemoryContext, rd_rulescxt);

Why do you think this is broken? While certainly not the prettiest code
around it looks ok to me. What it does is to keep the other entries data
around. Which we want if it's possibly referenced.

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [Report Bug With Patch] Rel Cache Bug
  2015-03-25 13:59 [Report Bug With Patch] Rel Cache Bug Jaimin Pan <jaimin.pan@gmail.com>
@ 2015-03-25 17:38 ` Tom Lane <tgl@sss.pgh.pa.us>
  2015-03-26 07:30   ` Re: [Report Bug With Patch] Rel Cache Bug Jaimin Pan <jaimin.pan@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2015-03-25 17:38 UTC (permalink / raw)
  To: Jaimin Pan <jaimin.pan@gmail.com>; +Cc: pgsql-bugs

Jaimin Pan <jaimin.pan@gmail.com> writes:
> I think there is a bug in rel cache rebuild of release 9.4.1.
> it also exists on some other release.

> the issue was introduced by 491dd4a97daa6b4de9ee8401ada10ad5da76af46

> -- a/src/backend/utils/cache/relcache.c
> +++ b/src/backend/utils/cache/relcache.c
> @@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool rebuild)
>                 /* ... but actually, we don't have to update newrel->rd_rel
> */
>                 memcpy(relation->rd_rel, newrel->rd_rel, CLASS_TUPLE_SIZE);
>                 /* preserve old tupledesc and rules if no logical change */
> -               if (keep_tupdesc)
> +               if (!keep_tupdesc)
>                         SWAPFIELD(TupleDesc, rd_att);
> -               if (keep_rules)
> +               if (!keep_rules)
>                 {
>                         SWAPFIELD(RuleLock *, rd_rules);
>                         SWAPFIELD(MemoryContext, rd_rulescxt);


You would need to provide a fairly convincing argument why you think that
five-year-old code is backwards.  Asserting there's a problem with
absolutely zero evidence is not likely to impress anyone.

(For the record, it did and does still look right to me.  As per the
comment about thirty lines up, what we're doing is un-swapping the
fields we don't want to change.  If keep_tupdesc is true, we don't
want to change rd_att, so we need to swap its old value back.
Likewise for the other thing.)

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [Report Bug With Patch] Rel Cache Bug
  2015-03-25 13:59 [Report Bug With Patch] Rel Cache Bug Jaimin Pan <jaimin.pan@gmail.com>
  2015-03-25 17:38 ` Re: [Report Bug With Patch] Rel Cache Bug Tom Lane <tgl@sss.pgh.pa.us>
@ 2015-03-26 07:30   ` Jaimin Pan <jaimin.pan@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Jaimin Pan @ 2015-03-26 07:30 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; andres@2ndquadrant.com; +Cc: pgsql-bugs

Thanks you for your replay.

I realized that i am wrong. I just miss the whole struct swap at the
beginning.
I am so sorry for bothering you with my fault.

2015-03-26 1:38 GMT+08:00 Tom Lane <tgl@sss.pgh.pa.us>:

> Jaimin Pan <jaimin.pan@gmail.com> writes:
> > I think there is a bug in rel cache rebuild of release 9.4.1.
> > it also exists on some other release.
>
> > the issue was introduced by 491dd4a97daa6b4de9ee8401ada10ad5da76af46
>
> > -- a/src/backend/utils/cache/relcache.c
> > +++ b/src/backend/utils/cache/relcache.c
> > @@ -2166,9 +2166,9 @@ RelationClearRelation(Relation relation, bool
> rebuild)
> >                 /* ... but actually, we don't have to update
> newrel->rd_rel
> > */
> >                 memcpy(relation->rd_rel, newrel->rd_rel,
> CLASS_TUPLE_SIZE);
> >                 /* preserve old tupledesc and rules if no logical change
> */
> > -               if (keep_tupdesc)
> > +               if (!keep_tupdesc)
> >                         SWAPFIELD(TupleDesc, rd_att);
> > -               if (keep_rules)
> > +               if (!keep_rules)
> >                 {
> >                         SWAPFIELD(RuleLock *, rd_rules);
> >                         SWAPFIELD(MemoryContext, rd_rulescxt);
>
>
> You would need to provide a fairly convincing argument why you think that
> five-year-old code is backwards.  Asserting there's a problem with
> absolutely zero evidence is not likely to impress anyone.
>
> (For the record, it did and does still look right to me.  As per the
> comment about thirty lines up, what we're doing is un-swapping the
> fields we don't want to change.  If keep_tupdesc is true, we don't
> want to change rd_att, so we need to swap its old value back.
> Likewise for the other thing.)
>
>                         regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2015-03-26 07:30 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 13:59 [Report Bug With Patch] Rel Cache Bug Jaimin Pan <jaimin.pan@gmail.com>
2015-03-25 17:08 ` Andres Freund <andres@2ndquadrant.com>
2015-03-25 17:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-03-26 07:30   ` Jaimin Pan <jaimin.pan@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox