Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 3DB0A9FB2C4 for ; Thu, 18 Jan 2007 20:12:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 69338-03 for ; Thu, 18 Jan 2007 20:12:35 -0400 (AST) X-Greylist: delayed 00:21:17.625704 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D02919FB383 for ; Thu, 18 Jan 2007 20:12:39 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.ncircle.com (mail.ncircle.com [64.84.9.150]) by svr4.postgresql.org (Postfix) with ESMTP id CA2F05AF970 for ; Thu, 18 Jan 2007 23:51:20 +0000 (GMT) Received: from exchange01.ad.ncircle.com (corp-mail01.ncircle.com [192.168.75.60]) by mail.ncircle.com (8.13.1/8.13.1) with ESMTP id l0INpCxT046428 for ; Thu, 18 Jan 2007 15:51:12 -0800 (PST) (envelope-from bcosentino@ncircle.com) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C73B5B.88DCE6D4" Subject: Help ... Unexpected results when using limit/offset with select statement..DB corruption? Date: Thu, 18 Jan 2007 15:51:12 -0800 Message-ID: <8A72E69E1F79004B82F76F228B3F29230637A623@corp-mail01.ncircle.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Help ... Unexpected results when using limit/offset with select statement..DB corruption? Thread-Index: Acc7W4h90elEZuhJS6egUlFwhOLCuQ== From: "Barbara Cosentino" To: X-Scanned-By: MIMEDefang 2.57 on 64.84.9.150 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200701/76 X-Sequence-Number: 27228 This is a multi-part message in MIME format. ------_=_NextPart_001_01C73B5B.88DCE6D4 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I got some weird results when processing select statements with limit and offset. I think its some kind of database corruption but I was wondering what other's think. =20 Background: =20 The table I'm having the issue with is described below. The thing to note is the primary key=20 =20 ice=3D# \d nc_host_datum Table "public.nc_host_datum" Column | Type | Modifiers ----------------------+---------+----------- host_id | bigint | not null host_datum_type_id | integer | not null host_datum_source_id | integer | not null data | text | not null Indexes: "nc_host_datum_pkey" PRIMARY KEY, btree (host_id, host_datum_type_id) Foreign-key constraints: "foreign_key_01" FOREIGN KEY (host_id) REFERENCES nc_host(host_id) ON UPDATE CASCADE ON DELETE CASCADE "foreign_key_02" FOREIGN KEY (host_datum_type_id) REFERENCES nc_host_datum_type(host_datum_type_id) ON UPDATE RESTRICT ON DELETE RESTRICT "foreign_key_03" FOREIGN KEY (host_datum_source_id) REFERENCES nc_host_datum_source(host_datum_source_id) ON UPDATE RESTRICT ON DELETE RESTRICT Problem: =20 I perform the following select (notice that the group by is by the primary key).=20 =20 select host_id, host_datum_type_id, count(*) =20 from nc_host_datum where host_id in ( select host_id=20 from nc_host=20 where audit_id=3D2041)=20 group by host_id, host_datum_type_id; =20 and get the following result (There are many more rows but these are all the rows for host_id =3D 963711): =20 host_id | host_datum_type_id | count=20 -------------+------------------------------+--------- 963711 | 58 | 1 963711 | 54 | 1 963711 | 39 | 1 963711 | 28 | 1 963711 | 27 | 1 =20 =20 Notice that there are 5 rows for host_id 963711 and the host_datum_type_id's are all unique=20 =20 Then I perform the following selects =20 SELECT host_id, host_datum_type_id, host_datum_source_id, data =20 FROM nc_host_datum INNER JOIN nc_host USING (host_id) =20 WHERE audit_id=3D2041 =20 ORDER BY host_id =20 LIMIT 49 OFFSET 1372; =20 And =20 =20 SELECT host_id, host_datum_type_id, host_datum_source_id, data =20 FROM nc_host_datum INNER JOIN nc_host USING (host_id) =20 WHERE audit_id=3D2041 =20 ORDER BY host_id =20 LIMIT 49 OFFSET 1421; =20 A portion of the output follows. =20 =20 host_id | host_datum_type_id | host_datum_source_id | data =20 ---------+--------------------+----------------------+-------------- : : =20 963710 | 58 | 17| harrish 963711 | 27 | 3 | 1 963711 | 28 | 3 | 1 (49 rows) =20 =20 host_id | host_datum_type_id | host_datum_source_id | data =20 ---------+--------------------+----------------------+-------------- 963711 | 28 | 3 | 1 963711 | 58 | 17 | lmitchel 963711 | 39 | 3 | us.aegon.com=20 : :=20 (49 rows) =20 Notice that host_id =3D 963711 and host_datum_type_id =3D 28 is repeated twice. Since the offset is not overlapping, how can this happen? Any ideas on how to fix this? =20 Thanks, =20 Barbara =20 =20 ------_=_NextPart_001_01C73B5B.88DCE6D4 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I got some weird results when processing select = statements with limit and offset.   I think its some kind of database = corruption but I was wondering what other’s = think.

 
Background:
 
The table I’m having =
the issue with is described below.  The thing to note is the =
primary key 
 
ice=3D# \d =
nc_host_datum
        Table =
"public.nc_host_datum"
        =
Column        |  =
Type   | Modifiers
----------------------+---------+-----------
 =
host_id           =
   | bigint  | not =
null
 host_datum_type_id   | integer | not =
null
 host_datum_source_id | integer | not =
null
 =
data           &nb=
sp;     | text    | not =
null
Indexes:
    "nc_host_datum_pkey" PRIMARY KEY, =
btree (host_id, =
host_datum_type_id)
Foreign-key =
constraints:
    "foreign_key_01" FOREIGN =
KEY (host_id) REFERENCES nc_host(host_id) ON UPDATE CASCADE ON DELETE =
CASCADE
    "foreign_key_02" FOREIGN =
KEY (host_datum_type_id) REFERENCES =
nc_host_datum_type(host_datum_type_id) ON UPDATE RESTRICT ON DELETE =
RESTRICT
    "foreign_key_03" FOREIGN =
KEY (host_datum_source_id) REFERENCES =
nc_host_datum_source(host_datum_source_id) ON UPDATE RESTRICT ON DELETE =
RESTRICT

Problem:
  =
I perform the following =
select (notice that the group by is by the primary key). =
 
select host_id, host_datum_type_id, =
count(*)   
from nc_host_datum where host_id =
in
  ( select host_id =
  from nc_host =
  where audit_id=3D2041) =
group by host_id, =
host_datum_type_id;
 
and get the following =
result (There are many more rows but these are all the rows for host_id =
=3D   963711):
 
host_id   | =
host_datum_type_id | count 
-------------+--------------=
----------------+---------
  963711 =
|            =
     =
58          =
 |     =
1
  963711 =
|            =
     =
54          =
 |     =
1
  963711 =
|            =
     =
39          =
 |     =
1
  963711 =
|            =
     28 =
          |  =
   1
  963711 =
|            =
     27 =
          |  =
   1
 
 
Notice that there are 5 =
rows for host_id 963711 and the host_datum_type_id's are all unique =
 
Then I perform the =
following selects
 
SELECT host_id, host_datum_type_id, =
host_datum_source_id, data  
FROM nc_host_datum  INNER JOIN nc_host USING =
(host_id)  
WHERE audit_id=3D2041  =
ORDER BY host_id  =
LIMIT 49 OFFSET =
1372;
 
And =
 
 
SELECT host_id, host_datum_type_id, =
host_datum_source_id, data  
FROM nc_host_datum  INNER JOIN nc_host USING =
(host_id)  
WHERE audit_id=3D2041  =
ORDER BY host_id  =
LIMIT 49 OFFSET =
1421;
 
A portion of the output =
follows.  
 
 host_id | host_datum_type_id | host_datum_source_id =
|     data     =
---------+--------------------+----------------------+=
--------------
  :
  :
 
  963710 =
|            =
     58 =
|            =
       17| =
harrish
  963711 |    =
            &=
nbsp;27 =
|            =
        3 | =
1
  963711 =
|            =
     28 =
|            =
        3 | =
1
(49 rows)
 
 
 host_id | host_datum_type_id | host_datum_source_id =
|     data     =
---------+--------------------+----------------------+=
--------------
  963711 =
|            =
     28 =
|            =
        3 | =
1
  963711 =
|            =
     58 =
|            =
       17 | =
lmitchel
  963711 =
|            =
     39 =
|            =
        3 | us.aegon.com =
:
: =
(49 rows)
 
Notice that host_id =3D =
963711 and host_datum_type_id =3D 28 is repeated twice.  Since the =
offset is not overlapping, how can this happen?  Any ideas on how =
to fix this?
 
Thanks,
 
Barbara
 

 

------_=_NextPart_001_01C73B5B.88DCE6D4--