Strange problem with create table as select * from table;

Started by hubert depesz lubaczewskiover 14 years ago41 messageshackersgeneral
Jump to latest
hackersgeneral

Hi
We have pretty weird situation, which seems to be impossible, but perhaps you'll notice something that will let me fix the problem.

System: SunOS 5.11 snv_130
Pg: PostgreSQL 8.4.7 on i386-pc-solaris2.11, compiled by cc: Sun C 5.10 SunOS_i386 2009/06/03, 64-bit

In there I have a table:

$ \d sssssss.xobjects
Table "sssssss.xobjects"
Column | Type | Modifiers
---------------------------+--------------------------+-----------------------------------------------------------------------
xobject_id | integer | not null default nextval('sssssss.xobjects_xobject_id_seq'::regclass)
magic_id | integer |
xxxxxxxxxxxxxx | integer |
xxxxxxxxxxxxx | integer |
creation_tsz | timestamp with time zone |
xxxx | character varying(255) |
xxxxxxxxxx | character varying(255) |
xxxxxxxxxxx | character varying(255) |
xxxx | character varying(255) |
xxxxx | character varying(255) |
xxx | character varying(255) |
xxxxxxxxxx | integer |
xxxxxxxxxxxxxx | character varying(128) |
xxxxxxxxxxxxx | character varying(255) |
xxxxxxxxxxxxxx | character varying(24) |
xxxxxxxxxxxxxxxxxxx | text |
xxxxxxxxxxxxxxxxxx | text |
xxxxxxxx | boolean | default false
xxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxx | character varying(6) | default 'USD'::character varying
xxxxxxxxxxxxxxxxxxxx | text |
xxxxxxxxxxx | boolean | default false
xxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxx | character varying(6) |
xxxxxxxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxx | boolean |
xxxxxxxxxxxxxxxx | integer |
xxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxx | bigint |
xxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxxxxx | numeric(24,2) |
xxxxxxxxxxxxxxxxx | integer |
xxxxxxxxxxxxxxxxxxxxxx | text |
xxxxxxxxx | character varying(255) |
xxxxxxx | integer |
xxxxxxxxxxxxxxxx | boolean |
xxxxxxxxxxxxxxxx | numeric(24,2) |
Indexes:
"xobjects_pkey" PRIMARY KEY, btree (xobject_id)
"xobjects_creation_tsz" btree (creation_tsz)

$ select * from pg_class where oid = 'sssssss.xobjects'::regclass;
-[ RECORD 1 ]--+-------------------------------------------------------------------------------------------
relname | xobjects
relnamespace | 9868449
reltype | 7441360
relowner | 10
relam | 0
relfilenode | 334123501
reltablespace | 0
relpages | 5534109
reltuples | 3.49685e+07
reltoastrelid | 334123504
reltoastidxid | 0
relhasindex | t
relisshared | f
relistemp | f
relkind | r
relnatts | 49
relchecks | 0
relhasoids | f
relhaspkey | t
relhasrules | f
relhastriggers | t
relhassubclass | f
relfrozenxid | 75260515
relacl | {postgres=arwdDxt/postgres,developer=r/postgres,sitemaps=r/postgres,uuuuuuu_ro=r/postgres}
reloptions | [null]

$ select * from pg_stat_user_tables where relid = 'sssssss.xobjects'::regclass;
-[ RECORD 1 ]----+------------------------------
relid | 7441358
schemaname | sssssss
relname | xobjects
seq_scan | 302
seq_tup_read | 8367856283
idx_scan | 34898129
idx_tup_fetch | 2836717789
n_tup_ins | 7772954
n_tup_upd | 1
n_tup_del | 5539090
n_tup_hot_upd | 1
n_live_tup | 35068206
n_dead_tup | 137275
last_vacuum | [null]
last_autovacuum | 2011-10-30 12:29:38.853241+00
last_analyze | [null]
last_autoanalyze | 2011-10-30 06:30:28.334954+00

This table looks perfectly OK. What's important - it doesn't have any duplicates in xobject_id column:

$ select xobject_id, count(*) from sssssss.xobjects group by 1 having count(*) > 1;
xobject_id | count
------------+-------
(0 rows)

All looks good. pg_dump of the table also doesn't show any strange problems, and is duplicate free. But:

$ create table zzz as select * from sssssss.xobjects;
SELECT

$ select xobject_id, count(*) from zzz group by 1 having count(*) > 1 order by 2 desc;
xobject_id | count
------------+-------
-1 | 40
(1 row)

$ select magic_id from zzz where xobject_id = -1 order by 1;
magic_id
----------
30343295
30343295
30408831
30408831
30408831
30539903
30605439
30605439
30670975
30670975
30670975
30802047
30867583
30933119
31195263
31195263
31260799
31326335
31588479
31588479
31588479
31654015
31719551
31785087
31785087
31785087
31850623
31850623
31850623
31850623
31981695
31981695
32047231
32047231
32112767
32309375
32374911
32440447
32505983
32505983
(40 rows)

What's interesting is that when I did it previously, couple of days ago, and sampled some randon magic_ids that I foudn with xobject_id = -1, I got:
$ select xobject_id, magic_id from zzz where magic_id in ( 32440447, 32047231, 32505983);
xobject_id | magic_id
------------+----------
35858705 | 32505983
35793169 | 32440447
-1 | 32440447
-1 | 32047231
-1 | 32505983
-1 | 32505983
35399951 | 32047231
-1 | 32047231
(8 rows)

please note that the same ids are duplicated now too.

and if magic_id was twice with xobject_id = -1, it is the same case now!.

In base sssssss.xobjects, all those rows are just once:

$ select xobject_id, magic_id from sssssss.xobjects where magic_id in (32440447, 32047231, 32505983);
xobject_id | magic_id
------------+----------
35858705 | 32505983
35793169 | 32440447
35399951 | 32047231
(3 rows)

I also verified that there are no concurrent updates that would set xobject_id to -1, so it's not a problem of isolation.

During the night I repeated the procedure and the rows that got duplicated seem to be the same - at the very least - the same magic_id.

Does above seem sensible for anyone? Any suggestions on what could be broken?

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#1)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thursday, November 03, 2011 1:25:58 am hubert depesz lubaczewski wrote:

Hi
We have pretty weird situation, which seems to be impossible, but perhaps
you'll notice something that will let me fix the problem.

System: SunOS 5.11 snv_130
Pg: PostgreSQL 8.4.7 on i386-pc-solaris2.11, compiled by cc: Sun C 5.10
SunOS_i386 2009/06/03, 64-bit

I also verified that there are no concurrent updates that would set
xobject_id to -1, so it's not a problem of isolation.

During the night I repeated the procedure and the rows that got duplicated
seem to be the same - at the very least - the same magic_id.

Does above seem sensible for anyone? Any suggestions on what could be
broken?

Do the xobject_id values have other negative numbers or is -1 just a special
case? The only thing I can think of is a corrupted index on xobject_id.

Best regards,

depesz

--
Adrian Klaver
adrian.klaver@gmail.com

In reply to: Adrian Klaver (#2)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 07:00:30AM -0700, Adrian Klaver wrote:

I also verified that there are no concurrent updates that would set
xobject_id to -1, so it's not a problem of isolation.

During the night I repeated the procedure and the rows that got duplicated
seem to be the same - at the very least - the same magic_id.

Does above seem sensible for anyone? Any suggestions on what could be
broken?

Do the xobject_id values have other negative numbers or is -1 just a special
case? The only thing I can think of is a corrupted index on xobject_id.

minimal xobject_id in source table is 1000.

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

$ explain select xobject_id, count(*) from sssssss.xobjects group by 1 having count(*) > 1;
QUERY PLAN
---------------------------------------------------------------------------------
GroupAggregate (cost=11718280.34..12682724.26 rows=35070688 width=4)
Filter: (count(*) > 1)
-> Sort (cost=11718280.34..11805957.06 rows=35070688 width=4)
Sort Key: xobject_id
-> Seq Scan on xobjects (cost=0.00..5884815.88 rows=35070688 width=4)
(5 rows)

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#4Alban Hertroys
haramrae@gmail.com
In reply to: hubert depesz lubaczewski (#3)
hackersgeneral
Re: Strange problem with create table as select * from table;

On 3 November 2011 15:15, hubert depesz lubaczewski <depesz@depesz.com> wrote:

Do the xobject_id values have other negative numbers or is -1 just a special
case? The only thing I can think of is a corrupted index on xobject_id.

minimal xobject_id in source table is 1000.

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

Actually, it does. A sequential scan doesn't use the index.

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In reply to: Alban Hertroys (#4)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 03:19:36PM +0100, Alban Hertroys wrote:

On 3 November 2011 15:15, hubert depesz lubaczewski <depesz@depesz.com> wrote:

Do the xobject_id values have other negative numbers or is -1 just a special
case? The only thing I can think of is a corrupted index on xobject_id.

minimal xobject_id in source table is 1000.

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

Actually, it does. A sequential scan doesn't use the index.

sure. but so isn't create table as.

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#3)
hackersgeneral
Re: Strange problem with create table as select * from table;

hubert depesz lubaczewski <depesz@depesz.com> writes:

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

I was just going to ask you to check that. Weird as can be.

Does plain old "SELECT COUNT(*)" show a difference between the two
tables?

Do you get similar misbehavior if you break the CREATE TABLE AS into a
CREATE and an INSERT/SELECT? Also, please note the rowcount returned
by INSERT/SELECT and see how it matches up with the tables afterwards.

Does turning synchronize_seqscans off affect the behavior?

regards, tom lane

In reply to: Tom Lane (#6)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 10:55:20AM -0400, Tom Lane wrote:

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

I was just going to ask you to check that. Weird as can be.
Does plain old "SELECT COUNT(*)" show a difference between the two
tables?

yes. the xobjects table is written to quite a lot and turning it off is
not an option.

Do you get similar misbehavior if you break the CREATE TABLE AS into a
CREATE and an INSERT/SELECT? Also, please note the rowcount returned
by INSERT/SELECT and see how it matches up with the tables afterwards.

Does turning synchronize_seqscans off affect the behavior?

interesting. will test and let you know. the test will take couple of
hours, though.

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#8Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#3)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thursday, November 03, 2011 7:15:22 am hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 07:00:30AM -0700, Adrian Klaver wrote:

I also verified that there are no concurrent updates that would set
xobject_id to -1, so it's not a problem of isolation.

During the night I repeated the procedure and the rows that got
duplicated seem to be the same - at the very least - the same
magic_id.

Does above seem sensible for anyone? Any suggestions on what could be
broken?

Do the xobject_id values have other negative numbers or is -1 just a
special case? The only thing I can think of is a corrupted index on
xobject_id.

minimal xobject_id in source table is 1000.

So just to be clear there is and never has been a -1 value for xobject_id in the
source table?
So a select count(*) from sssssss.xobjects where xobject_id = -1 on the source
table yields 0?

depesz

--
Adrian Klaver
adrian.klaver@gmail.com

In reply to: Adrian Klaver (#8)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 08:04:19AM -0700, Adrian Klaver wrote:

So just to be clear there is and never has been a -1 value for xobject_id in the
source table?

yes. min value of xobject_id is 1000, and we had trigger in place on the
table which logged all inserts/updates/deletes and the value -1 never
showed up (At least in the last couple of days, during which i was
making the copies).

So a select count(*) from sssssss.xobjects where xobject_id = -1 on the source
table yields 0?

yes, that's correct. both using index, and usingf seq scan.

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#10Alban Hertroys
haramrae@gmail.com
In reply to: hubert depesz lubaczewski (#1)
hackersgeneral
Re: Strange problem with create table as select * from table;

On 3 November 2011 09:25, hubert depesz lubaczewski <depesz@depesz.com> wrote:

All looks good. pg_dump of the table also doesn't show any strange problems, and is duplicate free. But:

$ create table zzz as select * from sssssss.xobjects;
SELECT

$ select xobject_id, count(*) from zzz group by 1 having count(*) > 1 order by 2 desc;
 xobject_id | count
------------+-------
        -1 |    40
(1 row)

Can you verify that these queries both do actually use a sequential
scan, and not, for some reason, an index scan? Just to rule out the
index corruption scenario.
You (or someone near you) might have disabled seqscans, for example.

Another thought: Is it possible that xobject_id just happens to be
used internally as a hidden field by Postgres or by an extension? That
would be another explanation for seeing -1 or duplicates in that
column.

If that's the case, I would have expected an error on creation of that table.

And lastly, is this behaviour after copying a table into a new one
reproducible or did it happen just once?

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

#11Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#9)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thursday, November 03, 2011 8:05:38 am hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 08:04:19AM -0700, Adrian Klaver wrote:

So just to be clear there is and never has been a -1 value for xobject_id
in the source table?

yes. min value of xobject_id is 1000, and we had trigger in place on the
table which logged all inserts/updates/deletes and the value -1 never
showed up (At least in the last couple of days, during which i was
making the copies).

So a select count(*) from sssssss.xobjects where xobject_id = -1 on the
source table yields 0?

yes, that's correct. both using index, and usingf seq scan.

Hmmm. Now we await the results of the tests Tom suggested. Just a thought, any
other strange behavior, hiccups in the database over the past couple of days?

Best regards,

depesz

--
Adrian Klaver
adrian.klaver@gmail.com

In reply to: Alban Hertroys (#10)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 04:21:37PM +0100, Alban Hertroys wrote:

On 3 November 2011 09:25, hubert depesz lubaczewski <depesz@depesz.com> wrote:

All looks good. pg_dump of the table also doesn't show any strange problems, and is duplicate free. But:

$ create table zzz as select * from sssssss.xobjects;
SELECT

$ select xobject_id, count(*) from zzz group by 1 having count(*) > 1 order by 2 desc;
 xobject_id | count
------------+-------
        -1 |    40
(1 row)

Can you verify that these queries both do actually use a sequential
scan, and not, for some reason, an index scan? Just to rule out the
index corruption scenario.
You (or someone near you) might have disabled seqscans, for example.

yes, i tested it with explain.

Another thought: Is it possible that xobject_id just happens to be
used internally as a hidden field by Postgres or by an extension? That
would be another explanation for seeing -1 or duplicates in that
column.

no. it's not a special field. just plain old "something_id", with
underscore, so it is not special in any way.

If that's the case, I would have expected an error on creation of that table.
And lastly, is this behaviour after copying a table into a new one
reproducible or did it happen just once?

fully reproductible, as i mentioned at the end of my original mail.

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

In reply to: Adrian Klaver (#11)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 08:23:01AM -0700, Adrian Klaver wrote:

On Thursday, November 03, 2011 8:05:38 am hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 08:04:19AM -0700, Adrian Klaver wrote:

So just to be clear there is and never has been a -1 value for xobject_id
in the source table?

yes. min value of xobject_id is 1000, and we had trigger in place on the
table which logged all inserts/updates/deletes and the value -1 never
showed up (At least in the last couple of days, during which i was
making the copies).

So a select count(*) from sssssss.xobjects where xobject_id = -1 on the
source table yields 0?

yes, that's correct. both using index, and usingf seq scan.

Hmmm. Now we await the results of the tests Tom suggested. Just a thought, any
other strange behavior, hiccups in the database over the past couple of days?

no. it's doing it's job without problems.

other tests are running, but simple question - how to get number of rows
affected from psql?

create table xxx as select * from xobjects;
returns just:
SELECT

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#13)
hackersgeneral
Re: Strange problem with create table as select * from table;

hubert depesz lubaczewski <depesz@depesz.com> writes:

other tests are running, but simple question - how to get number of rows
affected from psql?

create table xxx as select * from xobjects;
returns just:
SELECT

We fixed that in 9.0, but 8.4 won't provide the count (unless you care to
patch it). That's why I suggested doing a separate insert/select.

regards, tom lane

#15Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#13)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thursday, November 03, 2011 8:30:34 am hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 08:23:01AM -0700, Adrian Klaver wrote:

On Thursday, November 03, 2011 8:05:38 am hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 08:04:19AM -0700, Adrian Klaver wrote:

So just to be clear there is and never has been a -1 value for
xobject_id in the source table?

yes. min value of xobject_id is 1000, and we had trigger in place on
the table which logged all inserts/updates/deletes and the value -1
never showed up (At least in the last couple of days, during which i
was making the copies).

So a select count(*) from sssssss.xobjects where xobject_id = -1 on
the source table yields 0?

yes, that's correct. both using index, and usingf seq scan.

Hmmm. Now we await the results of the tests Tom suggested. Just a
thought, any other strange behavior, hiccups in the database over the
past couple of days?

no. it's doing it's job without problems.

other tests are running, but simple question - how to get number of rows
affected from psql?

See Toms answer

create table xxx as select * from xobjects;
returns just:
SELECT

The thing that has me puzzled is shown below from you original post:

$ select xobject_id, magic_id from zzz where magic_id in ( 32440447, 32047231,
32505983);
xobject_id | magic_id
------------+----------
35858705 | 32505983
35793169 | 32440447
-1 | 32440447
-1 | 32047231
-1 | 32505983
-1 | 32505983
35399951 | 32047231
-1 | 32047231
(8 rows)

Looks like multiple tuples of the same row where magic_id(s) of 32505983 and
32047231 where touched three times and 32440447 twice. For some reason the
original table is seeing only the most recent version while the CREATE AS is
pulling it and past versions. Some sort of visibility problem, exactly what is
beyond me at this point.

Best regards,

depesz

--
Adrian Klaver
adrian.klaver@gmail.com

In reply to: Tom Lane (#6)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thu, Nov 03, 2011 at 10:55:20AM -0400, Tom Lane wrote:

hubert depesz lubaczewski <depesz@depesz.com> writes:

index on xobject_id might be corrupted, but it doesn't explain that I
don't see duplicates with group_by/having query on xobjects, which uses
seqscan:

I was just going to ask you to check that. Weird as can be.

Does plain old "SELECT COUNT(*)" show a difference between the two
tables?

Do you get similar misbehavior if you break the CREATE TABLE AS into a
CREATE and an INSERT/SELECT? Also, please note the rowcount returned
by INSERT/SELECT and see how it matches up with the tables afterwards.

Does turning synchronize_seqscans off affect the behavior?

So, did some tests:

$ select count(*) from sssssss.xobjects;
count
----------
35179058
(1 row)

$ create table qqq as select * from sssssss.xobjects;
SELECT

$ select count(*) from qqq;
count
----------
35179631
(1 row)

$ select count(*) from qqq where xobject_id = -1;
count
-------
40
(1 row)

$ drop table qqq;
DROP TABLE

$ select count(*) from sssssss.xobjects;
count
----------
35182687
(1 row)

$ create table qqq ( like sssssss.xobjects );
CREATE TABLE

$ insert into qqq select * from sssssss.xobjects;
INSERT 0 35182962

$ select count(*) from qqq;
count
----------
35182962
(1 row)

$ select count(*) from qqq where xobject_id = -1;
count
-------
40
(1 row)

$ drop table qqq;
DROP TABLE

$ set synchronize_seqscans = off;
SET

$ create table qqq as select * from sssssss.xobjects;

SELECT
$ select count(*) from qqq;
count
----------
35185653
(1 row)

$ select count(*) from qqq where xobject_id = -1;
count
-------
40
(1 row)

$ drop table qqq;
DROP TABLE

$ create table qqq ( like sssssss.xobjects );
CREATE TABLE

$ insert into qqq select * from sssssss.xobjects;
INSERT 0 35188896

$ select count(*) from qqq;
count
----------
35188896
(1 row)

$ select count(*) from qqq where xobject_id = -1;
count
-------
40
(1 row)

$ drop table qqq;
DROP TABLE

as you can see counts of rows in created table are more or less
sensible, but whatever method I used - create table as, insert into,
using sychronized_scans (initially) or not (later) - copy of the table,
as long as it's in database, has 40 those "-1" rows.

one note - maybe it wasn't clear from my original mail - when I did
pg_dump of the xobjects table, it didn't have -1 rows.

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#17Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#16)
hackersgeneral
Re: Strange problem with create table as select * from table;

On Thursday, November 03, 2011 1:03:12 pm hubert depesz lubaczewski wrote:

On Thu, Nov 03, 2011 at 10:55:20AM -0400, Tom Lane wrote:

So, did some tests:

as you can see counts of rows in created table are more or less
sensible, but whatever method I used - create table as, insert into,
using sychronized_scans (initially) or not (later) - copy of the table,
as long as it's in database, has 40 those "-1" rows.

At least it is consistent:)
Characteristics of those forty rows.
1) creation_tsz clustered?
2) magic_id in a range?
3) Non -1 xobject_id in a range?
4) Any other field show a similarity?

one note - maybe it wasn't clear from my original mail - when I did
pg_dump of the xobjects table, it didn't have -1 rows.

--
Adrian Klaver
adrian.klaver@gmail.com

#18Tom Lane
tgl@sss.pgh.pa.us
In reply to: Adrian Klaver (#17)
hackersgeneral
Re: Strange problem with create table as select * from table;

Adrian Klaver <adrian.klaver@gmail.com> writes:

On Thursday, November 03, 2011 1:03:12 pm hubert depesz lubaczewski wrote:

as you can see counts of rows in created table are more or less
sensible, but whatever method I used - create table as, insert into,
using sychronized_scans (initially) or not (later) - copy of the table,
as long as it's in database, has 40 those "-1" rows.

At least it is consistent:)

Yeah, it wasn't clear before, but it looks like there are specific
rows that there's something wrong with.

Characteristics of those forty rows.
1) creation_tsz clustered?
2) magic_id in a range?
3) Non -1 xobject_id in a range?
4) Any other field show a similarity?

I would like to know the ctid's of the -1 rows in the copied table,
along with the ctid's of the rows they share magic_ids with, and
the ctid's of the rows with those same magic_ids in the original.
I'm wondering whether the affected rows are physically clustered ...

regards, tom lane

In reply to: Tom Lane (#18)
hackersgeneral
Re: Strange problem with create table as select * from table;

I would like to know the ctid's of the -1 rows in the copied table,
along with the ctid's of the rows they share magic_ids with, and
the ctid's of the rows with those same magic_ids in the original.
I'm wondering whether the affected rows are physically clustered ...

i tried:
create table qqq as select cmax as o_cmax, xmax as o_xmax, cmin as
o_cmin, xmin as o_xmin, ctid as o_ctid, * from sssssss.xobjects;

but the resulting table didn't have -1 values:
$ select xobject_id, count(*) from qqq group by 1 having count(*) > 1;
xobject_id | count
------------+-------
(0 rows)

$ select o_cmax,o_xmax,o_cmin,o_xmin,o_ctid, xobject_id, order_id from qqq where xobject_id = -1;
o_cmax | o_xmax | o_cmin | o_xmin | o_ctid | xobject_id | order_id
--------+--------+--------+--------+--------+------------+----------
(0 rows)

i'm checking now something else, but later will try to get better grasp on those bad rows.

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

#20Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#19)
hackersgeneral
Re: Strange problem with create table as select * from table;

hubert depesz lubaczewski <depesz@depesz.com> writes:

i tried:
create table qqq as select cmax as o_cmax, xmax as o_xmax, cmin as
o_cmin, xmin as o_xmin, ctid as o_ctid, * from sssssss.xobjects;

but the resulting table didn't have -1 values:

Oh, that's pretty interesting ... suggests that the targetlist has to be
exactly "select *". We have some minor optimizations for that case,
though nothing that could result in extra rows AFAICS.

Are there any dropped columns in the original table? Try

select * from pg_attribute where attrelid = 'sssssss.xobjects'::regclass
and attisdropped;

regards, tom lane

In reply to: Tom Lane (#20)
hackersgeneral
In reply to: hubert depesz lubaczewski (#21)
hackersgeneral
#23Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#22)
hackersgeneral
In reply to: Adrian Klaver (#23)
hackersgeneral
#25Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#24)
hackersgeneral
#26Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#22)
hackersgeneral
In reply to: Tom Lane (#26)
hackersgeneral
#28Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#26)
hackersgeneral
In reply to: Tom Lane (#28)
hackersgeneral
In reply to: Tom Lane (#26)
hackersgeneral
#31Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#30)
hackersgeneral
#32Adrian Klaver
adrian.klaver@aklaver.com
In reply to: hubert depesz lubaczewski (#30)
hackersgeneral
#33Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#31)
hackersgeneral
#34Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Tom Lane (#33)
hackersgeneral
In reply to: Tom Lane (#26)
hackersgeneral
In reply to: Adrian Klaver (#32)
hackersgeneral
#37Martijn van Oosterhout
kleptog@svana.org
In reply to: Tom Lane (#33)
hackersgeneral
In reply to: Tom Lane (#33)
hackersgeneral
#39Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#38)
hackersgeneral
#40Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#38)
hackersgeneral
In reply to: Tom Lane (#39)
hackersgeneral