Re: row_to_json bug with index only scans: empty keys! - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: row_to_json bug with index only scans: empty keys!
Date
Msg-id 545CF0AC.9040809@dunslane.net
Whole thread Raw
In response to row_to_json bug with index only scans: empty keys!  (Ross Reedstrom <reedstrm@rice.edu>)
Responses Re: row_to_json bug with index only scans: empty keys!  (Andrew Dunstan <andrew@dunslane.net>)
Re: row_to_json bug with index only scans: empty keys!  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 11/07/2014 10:51 AM, Ross Reedstrom wrote:
> This is a serious bug in 9.3.5 and 9.4 beta3:
>
> row_to_json() yields empty strings for json keys if the data is
> fulfilled by an index only scan.
>
> Example:
>
> testjson=# select count(*) from document_acl;
>   count
> -------
>     426
> (1 row)
>
> testjson=# SELECT row_to_json(combined_rows) FROM (
> SELECT uuid, user_id AS uid, permission
> FROM document_acl_text AS acl
> WHERE uuid = '8f774048-8936-4d7f-aa38-1974c91bbef2'
> ORDER BY user_id ASC, permission ASC
> ) as combined_rows;
>                               row_to_json
> ---------------------------------------------------------------------
>   {"":"8f774048-8936-4d7f-aa38-1974c91bbef2","":"admin","":"publish"}


That seems odd. Here's what the relevant code does:
        td = DatumGetHeapTupleHeader(composite);
        /* Extract rowtype info and find a tupdesc */        tupType = HeapTupleHeaderGetTypeId(td);        tupTypmod =
HeapTupleHeaderGetTypMod(td);       tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
 
   ...        for (i = 0; i < tupdesc->natts; i++)     ...
            attname = NameStr(tupdesc->attrs[i]->attname);            escape_json(result, attname);

Could this be a bug in lookup_rowtype_tupdesc()?


cheers

andrew



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: recovery_target_time and standby_mode
Next
From: Atri Sharma
Date:
Subject: Re: Representing a SRF return column in catalogs