Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU6D3-0004w4-MK for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Apr 2021 11:18:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lU6D2-0001MO-Mh for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Apr 2021 11:18:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU5uM-0002S3-Qp for pgsql-bugs@lists.postgresql.org; Wed, 07 Apr 2021 10:59:39 +0000 Received: from mail1.politie.nl ([2a04:9a00:1200:a610::13]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU5uJ-0000gn-KM for pgsql-bugs@lists.postgresql.org; Wed, 07 Apr 2021 10:59:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=politie.nl; i=@politie.nl; q=dns/txt; s=20170705; t=1617793175; x=1649329175; h=from:to:subject:date:message-id:mime-version; bh=AIunKP6cMrLswKZ/jHVfQxBFClNtSjh9C/aCvu7GsSM=; b=WeNkxVRTgmVU45oLeywROHKqYJF4a3SNz2jUygAbdrXx6HadMuG8VzeG vR5qI998kdswK0Woa/mmuCbmAvIZ1F9pGth6/NhFA6jLQ/x4Gmjh7gJlj +Vy+70fBjIryAmMyG4+nfbWWeGwEGVkJtZmgONQW7Pl6ALzmy7odiVplT s=; IronPort-SDR: 8AcZPGcMC8XWJ2h69pKSf5jkSYxfF9rOuqZyPCpCrm8kfE/LTVLHhrNn2zjY/wN1Ec6C2ubFRZ 9axzBkcWO7oQ== From: "Poot, Bas (B.J.)" To: "pgsql-bugs@lists.postgresql.org" Subject: XX000: unknown type of jsonb container. Thread-Topic: XX000: unknown type of jsonb container. Thread-Index: AQHXKwoni8ssrorZL0+gQ0h5oteWug== Date: Wed, 7 Apr 2021 10:59:31 +0000 Message-ID: <534fca83789c4a378c7de379e9067d4f@politie.nl> Accept-Language: nl-NL, en-US Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.72.117] Content-Type: multipart/alternative; boundary="_000_534fca83789c4a378c7de379e9067d4fpolitienl_" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_534fca83789c4a378c7de379e9067d4fpolitienl_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi there, First of all I must say that we're not only very thankful for the work you = guys are doing. But also very impressed with the result. We have various products using various databases, and coming from an oracle= database I must say I'm overwhelmed by the performance and features postgr= es has. Unfortunately we're experiencing very weird behavior upgrading to postgres = 13, and possibly found a bug. This is going to be a weird bug report, but please keep reading. Recently we migrated our postgres test database. We had a postgres 12.5 on = windows, and moved to a postgres 13.2.1 on ubuntu 20 (clustered). 99% of all queries worked just fine, but one particular query created an ex= ception: XX000: unknown type of jsonb container. We did some various testing with various versions of postgres on various op= erating systems (Ubuntu and windows server 2016) We found that we can reproduce the bug in both ubuntu 20 and windows 2016 w= ith postgres 13.2.1. Also we didn't have the problem with postgres 12.5 or 12.6 on both windows = and ubuntu. So it seems to be a 13.x bug (we didn't try lower versions of 13 then 13.2.= 1) Of course the first thing I did was run the query in a different tool (we u= se DBeaver) and I got the same result. I tried to reduce the query, by stripping columns, rows etc. figure out wha= t part of it created the error. I got as far as this: select display_name, '' as rolename ,filtur ,jsonb_each_text(filtur) as x ,to_jsonb(jsonb_each_text(filtur)) as frows ,array(SELECT jsonb_object_keys(filtur)) as objectkeys from tmp_bug2 order by logical_name ; where our 'tmp_bug2' table is a select into from a lot of joins on other ta= bles. The DDL is now this: CREATE TABLE public.tmp_bug2 ( logical_name varchar NULL, display_name varchar NULL, filtur jsonb NULL ); But now the weird stuff started happening. (tldr: testcase at the end of th= is mail) I can do a lot of changes on this query that makes me get a different excep= tion (or no exception at all). But when I wait a bit, or change some random= ly other line I get the error again. Weird behavior 1: When the tmp_bug2 table has these rows: - logical_name - display_name - operation - filtur And I remove the 'display_name' from the query, it works. I get no more err= ors and see data. Then I figured that i don't use the column 'operation' at all, so i removed= it from my tmp_bug2 table (dropped it, and redid the select into). The table now contains these columns: - logical_name - display_name - filtur When I run the query it still fails. But now, when I remove the 'display_na= me' field from my select, it keeps failing. So the removing of the 'operati= on' column in my table somehow changes the behavior of my query. Even when I don't use the entire column. Weird behavior 2: (based on the original query) When I remove the line '' as rolename, I get a perfectly fine result. No errors, it all works. So removing a totally useless column makes my query work. Weird behavior 3: When I remove 'order by' clause my query works again like a charm. No error= s whatsoever. But that's weird, because my select into query also has an order by. Therefor the table 'tmp_bug2' is already sorted by logical_name. I can imagine some operations only being done on the lines you return to yo= ur client, but the data is ordered in the same way, so I should return the = same rows. With or without that order by statement Weird behavior 4 In our original query, we have the last 3 columns in the select that do stu= ff with json(b) functions. ,jsonb_each_text(filtur) as x ,to_jsonb(jsonb_each_text(filtur)) as frows ,array(SELECT jsonb_object_keys(filtur)) as objectkeys obviously this error has something to do with those statements. So I tried to comment out the first line: still an error. I tried to comment out the second one (instead of the first) still an error= . Then I commented out both of them. Problem solved, query works! Then enabled them all, and commented out the 3th line. Problem solved again= . So: when I have the first or second line active we get an error. when I have the 3th line active we get an error when we disable the 3th line it works (even with the first and second line = active) Weird behavior 5 Now I tried to figure out in what row triggers the error. first I created a table that contained all the information in my original s= ubquery (not in this email) and called it tmp_bug. Then I did this: select * into tmp_bug2 from ( select logical_name , display_name , operation , filtur from tmp_bug order by logical_name ) t1 limit 300000 ; note that I order by logical_name, and limit my rows, so I only get 300k of= my 390k rows. So I only lose 90k rows. When I run my query (top of this email) it works like a charm. Therefor I c= oncluded, the error must be in the 90k rows I dropped. So I dropped my tmp_bug2 table, and redid the above query, but then alterin= g the order by clause using: order by logical_name desc this way I dropped the first 90K rows, instead of the last 90K. I reran my query, and (wtf) it again worked like a charm.. So somehow it has nothing to do with the specific rows I select.... Weird behavior 6 In an attempt to create a testcase with the same amount of rows I tried upd= ating them all to the same value. So I updated the columns 'display_name' and 'logical_name' to 'thing' and t= he the case still stands (errors as above) I simplified my select into statement to generate the table, so it now alwa= ys added 'thing' into those 2 columns. Results as expected. Still errors. (but closer to a testcase for you guys) Then I updated the column 'filtur' like so: update tmp_bug2 set filtur =3D '{"unit": "Our special Unit", "some.place": "placename", "p= lace_of_birth": "Over the rainbow", "How_secret_is_it": "Level 1", "Does.it= .shoot": "YES!"}'::jsonb And again the case still stands. Errors as above. So I simplified my select into statement just as with the other to columns.= It was now sort of like this: select * into tmp_bug2 from ( select logical_name , 'thing' as display_name , 'thing' as operation , '{"unit": "Our special Unit", "some.place": "placename", "place_of_birth"= : "Over the rainbow", "How_secret_is_it": "Level 1", "Does.it.shoot": "YES!= "}'::jsonb as filtur from ( .. complex subquery here.. ) order by logical_name ) t1 And suddenly all queries ran fine. No more errors. I removed my simplification, and went back to select * into tmp_bug2 from ( select logical_name , 'thing' as display_name , 'thing' as operation , filtur from ( .. complex subquery here.. ) order by logical_name ) t1 and the errors were back. Then I updated the table using the above update statement, and again: error= s remained.. I had the same problem updating the logical_name column, when I used the up= date (after creating the table) I still had the error. But when I created t= he table with the static value ('thing' in my case) the errors were suddenl= y gone So creating a table with a value has a different result then creating a tab= le with a value, and then updating that value.. Weird behavior 7 Finally! I have a testcase for you guys. This is my query to generate the d= ata. select * into tmp_bug2 from ( select 'thing' as logical_name , 'thing' as display_name , 'thing' as operation , '{"unit": "Our special Unit", "some.place": "placename", "place_of_birth"= : "Over the rainbow", "How_secret_is_it": "Level 1", "Does.it.shoot": "YES!= "}'::jsonb as filtur from generate_series(1, 302443) ) t1; And this is the query that generates the error. select display_name ,'' as x ,filtur ,jsonb_each_text(filtur) as x ,to_jsonb(jsonb_each_text(filtur)) as frows ,array(SELECT jsonb_object_keys(filtur)) as objectkeys from tmp_bug2 order by logical_name; Notice that when you generate not 302443 but 302442 rows, it works perfectl= y fine. I'm lost here. And I sure as hell would like a hand Bas ------------------------- Disclaimer ---------------------------- De informatie verzonden met dit e-mailbericht (en bijlagen) is uitsluitend = bestemd voor de geadresseerde(n) en zij die van de geadresseerde(n) toestem= ming kregen dit bericht te lezen. Kennisneming door anderen is niet toegestaan. De informatie in dit e-mailbericht (en bijlagen) kan vertrouwelijk van aard= zijn en binnen het bereik van een geheimhoudingsplicht en/of een verschoni= ngsrecht vallen. Indien dit e-mailbericht niet voor u bestemd is, wordt u verzocht de afzend= er daarover onmiddellijk te informeren en het e-mailbericht (en bijlagen) t= e vernietigen. Conform het beveiligingsbeleid van de Politie wordt e-mail van en naar de p= olitie gecontroleerd op virussen, spam en phishing en moet deze e-mail vold= oen aan de voor de overheid verplichte mailbeveiligingsstandaarden die zijn= vastgesteld door het Forum Standaardisatie. Mail die niet voldoet aan het beveiligingsbeleid kan worden geblokkeerd waa= rdoor deze de geadresseerde niet bereikt. De geadresseerde wordt hiervan ni= et in kennis gesteld. --------------------------------------------------------------------- The information sent in this E-mail message (including any attachments) is = exclusively intended for the individual(s) to whom it is addressed and for = the individual(s) who has/have had permission from the recipient(s) to read= this message. Access by others is not permitted. The information in this E-mail message (including any attachments) may be o= f a confidential nature and may form part of the duty of confidentiality an= d/or the right of non-disclosure. If you have received this E-mail message in error, please notify the sender= without delay and delete the E-mail message (including any attachments). In conformity with the security policy of the Police, E-mails from and to t= he Police are checked for viruses, spam and phishing and this E-mail must m= eet the standards of the government-imposed E-mail security as set by the S= tandardization Forum. Any E-mail failing to meet said security policy may be blocked as a result = of which it will not reach the intended recipient. The recipient concerned = will not be notified. --------------------------------------------------------------------- --_000_534fca83789c4a378c7de379e9067d4fpolitienl_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi there,

First of all I must say that we're not only very thankful for the work you = guys are doing. But also very impressed with the result.
We have various products using various databases, and coming from an oracle= database I must say I'm overwhelmed by the performance and features postgr= es has.

Unfortunately we're experiencing very weird behavior upgrading to postgres = 13, and possibly found a bug.


This is going to be a weird bug report, but please keep reading.

Recently we migrated our postgres test database. We had a postgres 12.= 5 on windows, and moved to a postgres 13.2.1 on ubuntu 20 (clustered).=

99% of all queries worked just fine, but one particular query created an ex= ception: XX000: unknown type of jsonb container.

We did some various testing with various versions of postgres on various op= erating systems (Ubuntu and windows server 2016)
We found that we can reproduce the bug in both ubuntu 20 and windows 2016 w= ith postgres 13.2.1.

Also we didn't have the problem with postgres 12.5 or 12.6 on both windows = and ubuntu.
So it seems to be a 13.x bug (we didn't try lower versions of 13 then 13.2.= 1)


Of course the first thing I did was run the query in a different tool = (we use DBeaver) and I got the same result.
I tried to reduce the query, by stripping columns, rows etc. figure ou= t what part of it created the error.  I got as far as this:

 
 
select 
display_name,
'' as rolename
,filtur
,jsonb_each_text(filtur) as x
,to_jsonb(jsonb_each_text(filtur)) as frows
,array(SELECT jsonb_object_keys(filtur)) as objectkeys
from tmp_bug2
order by logical_name
;
 

where our 'tmp_bug2' table is a select into from a lot of joins on other ta= bles. The DDL is now this:

CREATE TABLE public.tmp_bug2 (
logical_name varchar NULL,
display_name varchar NULL,
filtur jsonb NULL
);



But now the weird stuff started happe= ning. (tldr: testcase at the end of this mail)

I can do a lot of changes on this query that makes me get a different excep= tion (or no exception at all). But when I wait a bit, or change some random= ly other line I get the error again.

Weird behavior 1:
When the tmp_bug2 table has these rows:
- logical_name
- display_name
- operation
- filtur=
And I remove the 'display_name' fro= m the query, it works. I get no more errors and see data.
 

Then I figured that i don't use the column 'operation' at all, so i removed= it from my tmp_bug2 table (dropped it, and redid the select into).
The table now contains these columns:
 
- logical_name
- display_name
- filtur

 
When I run the query it still fails. But now, when I remove the 'display_na= me' field from my select, it keeps failing. So the removing of the 'operati= on' column in my table somehow changes the behavior of my query.
Even when I don't use the entire column.



Weird behavior 2:
(based on the original query)
When I remove the line 
'' as rolename,

I get a perfectly fine result. No errors, it all works.
 
So removing a totally useless column makes my query work.



Weird behavior 3:
When I remove 'order by' clause my query works again like a charm. No error= s whatsoever.
But that's weird, because my select into query also has an order by.
Therefor the table 'tmp_bug2' is already sorted by logical_name. 
I can imagine some operations only being done on the lines you return to yo= ur client, but the data is ordered in the same way, so I should return the = same rows.
With or without that order by statement



Weird behavior 4=
In our original query, we have th= e last 3 columns in the select that do stuff with json(b) functions. 
,jsonb_each_text(filtur) as x
,to_jsonb(jsonb_each_text(filtur)) as frows
,array(SELECT jsonb_object_keys(filtur)) as objectkeys

obviously this error has something to= do with those statements.
So I tried to comment out = the first line: still an error.
I tried to <= span style=3D"font-size:16px">comment out the second one (instead of the first) still an error.
Then I commented out both of them. Pr= oblem solved, query works!
Then enabled them all, and commented = out the 3th line. Problem solved again.

So:
when I have the first or second line = active we get an error.
when I have the 3th line active we get an error
when we disable the 3th line it works (even with the first and second line = active)



Weird behavior 5
Now I tried to figure out in what row triggers the error.

first I created a table that contained all the information in my original s= ubquery (not in this email) and called it tmp_bug.
Then I did this:
select *
into tmp_bug2
from (
select logical_name
, display_name
, operation
, filtur
from tmp_bug
order by logical_name 
) t1
limit 300000
;

note that I order by logical_name, an= d limit my rows, so I only get 300k of my 390k rows.
So I only lose 90k rows.
When I run my query (top of this emai= l) it works like a charm. Therefor I concluded, the error must be in the 90k rows I dropped.

So I dropped my tmp_bug2 table, and r= edid the above query, but then altering the order by clause using:
order by logical_name desc<= /font>
this way I dropped the first 90K rows= , instead of the last 90K. 
I reran my query, and (wtf) it again worked like a charm..
So somehow it has nothing to do with the specific rows I select....


Weird behavior 6
In an attempt to create a testcase with the same amount of ro= ws I tried updating them all to the same value.
So I updated the columns 'display_name' and 'logical_name' to= 'thing' and the the case still stands (errors as above)
I simplified my select into statement to generate the table, so it now always added 'th= ing' into those 2 columns.
Results as expected. Still errors. (but closer = to a testcase for you guys)

Then I updated the column 'filtur' like so:

update tmp_bug2 
set filtur  =3D '{"unit": "Our special Unit&quo= t;, "some.place": "placename", "place_of_birth&quo= t;: "Over the rainbow", "How_secret_is_it": "Level= 1", "Does.it.shoot": "YES!"}'::jsonb

And again the case still stands. Errors as above.
So I simplified my select into statement just as with the other to columns.= It was now sort of like this:

select *

into tmp_bug2

from (

select logical_name
, 'thing' as display_name
, 'thing' as operation
, '{"unit": "Our special Unit", "some.place&quo= t;: "placename", "place_of_birth": "Over the rainb= ow", "How_secret_is_it": "Level 1", "Does.it.= shoot": "YES!"}'::jsonb as filtur
from ( .. complex subquery here.. )
order by logical_name 

) t1


And suddenly all queries ran fine. No more errors.
I removed my simplification, and went back to

select *

into tmp_bug2

from (

select logical_name
, 'thing' as display_name
, 'thing' as operation
, filtur
from ( .. complex subquery here.. )
order by logical_name 

) t1

and the errors were back.
Then I updated the table using the above update statement, and again: = errors remained..

I had the same problem updating the logical_name column,= when I used the update (after creating the table) I still had the error. But when I created the table with the static value ('thing'= in my case) the errors were suddenly gone

So creating a table with a value has a different result then creating = a table with a value, and then updating that value..


Weird behavior 7

Finally! I have a testcase for you guys. This is my query to generat= e the data.
select *
into tmp_bug2
from (
select 'thing' as  logical_name
, 'thing' as display_name
, 'thing' as operation
, '{"unit": "Our special = Unit", "some.place": "placename", "place_of_b= irth": "Over the rainbow", "How_secret_is_it": "Level 1", "Does.it.shoot&quo= t;: "YES!"}'::jsonb as filtur
from generate_series(1, 302443)
) t1;

And this is the query that generates the error.

select 
display_name
,'' as x
,filtur
,jsonb_each_text(filtur) as x=
,to_jsonb(jsonb_each_text(fil= tur)) as frows
,array(SELECT jsonb_object_ke= ys(filtur)) as objectkeys
from tmp_bug2
order by logical_name;

Notice that when you generate not 302443 bu= t 302442 rows, it works perfectly fine.




I'm lost here.
And I sure as hell would like a hand

Bas

------------------------- Disclaimer ----------------------------
De informatie verzonden met dit e-mailbericht (en bijlagen) is uitsluitend = bestemd voor de geadresseerde(n) en zij die van de geadresseerde(n) toestem= ming kregen dit bericht te lezen.
Kennisneming door anderen is niet toegestaan.
De informatie in dit e-mailbericht (en bijlagen) kan vertrouwelijk van aard= zijn en binnen het bereik van een geheimhoudingsplicht en/of een verschoni= ngsrecht vallen.
Indien dit e-mailbericht niet voor u bestemd is, wordt u verzocht de afzend= er daarover onmiddellijk te informeren en het e-mailbericht (en bijlagen) t= e vernietigen.
Conform het beveiligingsbeleid van de Politie wordt e-mail van en naar de p= olitie gecontroleerd op virussen, spam en phishing en moet deze e-mail vold= oen aan de voor de overheid verplichte mailbeveiligingsstandaarden die zijn= vastgesteld door het Forum Standaardisatie.
Mail die niet voldoet aan het beveiligingsbeleid kan worden geblokkeerd waa= rdoor deze de geadresseerde niet bereikt. De geadresseerde wordt hiervan ni= et in kennis gesteld.
---------------------------------------------------------------------
The information sent in this E-mail message (including any attachments) is = exclusively intended for the individual(s) to whom it is addressed and for = the individual(s) who has/have had permission from the recipient(s) to read= this message.
Access by others is not permitted.
The information in this E-mail message (including any attachments) may be o= f a confidential nature and may form part of the duty of confidentiality an= d/or the right of non-disclosure.
If you have received this E-mail message in error, please notify the sender= without delay and delete the E-mail message (including any attachments). In conformity with the security policy of the Police, E-mails from and to t= he Police are checked for viruses, spam and phishing and this E-mail must m= eet the standards of the government-imposed E-mail security as set by the S= tandardization Forum.
Any E-mail failing to meet said security policy may be blocked as a result = of which it will not reach the intended recipient. The recipient concerned = will not be notified.
---------------------------------------------------------------------
--_000_534fca83789c4a378c7de379e9067d4fpolitienl_--