Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aJBE5-00077x-RT for pgsql-admin@arkaria.postgresql.org; Wed, 13 Jan 2016 02:31:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aJBE5-0001Yp-Dh for pgsql-admin@arkaria.postgresql.org; Wed, 13 Jan 2016 02:31:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aJBCF-0005kM-MZ for pgsql-admin@postgresql.org; Wed, 13 Jan 2016 02:30:03 +0000 Received: from snt004-omc1s26.hotmail.com ([65.55.90.37]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aJBCB-00005H-Hf for pgsql-admin@postgresql.org; Wed, 13 Jan 2016 02:30:03 +0000 Received: from SNT147-W50 ([65.55.90.7]) by SNT004-OMC1S26.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 12 Jan 2016 18:29:56 -0800 X-TMN: [3YeKAODwnWJv7zNKjKkFyH1A3yjm79wQ] X-Originating-Email: [smerlo50@outlook.com] Message-ID: Content-Type: multipart/alternative; boundary="_985078f1-ddbe-484f-a35f-6b758f532256_" From: Saulo Merlo To: "pgsql-admin@postgresql.org" Subject: Query - Create PostgreSQL Date: Wed, 13 Jan 2016 02:29:56 +0000 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 13 Jan 2016 02:29:56.0603 (UTC) FILETIME=[4AD9ECB0:01D14DAA] X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org --_985078f1-ddbe-484f-a35f-6b758f532256_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable So.. I have a Query that is taking too long to complete. OLD QUERY: SELECT file.inode_id AS file_id=2C file.parent_inode_id AS file_= group=2C file.relative_path AS file_type=2C file.file_data AS fil= e_binary=2C file.node_full_path AS file_name=2C file.last_modified AS = date_createdFROM gorfs.nodes AS file INNER JOIN gorfs.inode_segments AS = iseg ON iseg.st_ino =3D file.parent_inode_id = AND file.object_type =3D 'S_IFREG' AND = iseg.nfs_migration_date IS NULL AND (file.= last_modified < (transaction_timestam= p() AT TIME ZONE 'UTC' - '1 months' :: INTERVAL)) = AND iseg.st_ino_target =3D file.inode_idLIMIT 100=3B We created a new temporary table to store migrations=2C which may be the be= st option (no longer need to join new columns in query).I just need the sam= e output as any of the correct above one. NEW QUERY STRUCTURE: table: gorfs.nfs_data: CREATE TABLE gorfs.nfs_data( owner_id integer NOT NULL=2C file_id integer= NOT NULL=2C migration_path "text"=2C migration_date timestamp with time = zone=2C CONSTRAINT nfs_data_pkey PRIMARY KEY ("file_id")) INDEX:=20 CREATE INDEX ix_nfs_data_owner_id ON gorfs.nfs_data USING btree ("owner_= id") WHERE "migration_date" IS NULL=3B OLD EXPLAIN ANALYZE (Using the OLD query):Link: http://explain.depesz.com/s= /Swu COLUMNS:ALTER TABLE gorfs.nfs_data ADD COLUMN owner_id integer=3BALTER TABL= E gorfs.nfs_data ALTER COLUMN owner_id SET NOT NULL=3BALTER TABLE gorfs.nfs= _data ADD COLUMN file_id integer=3BALTER TABLE gorfs.nfs_data ALTER COLUMN = file_id SET NOT NULL=3BALTER TABLE gorfs.nfs_data ADD COLUMN migration_path= "text"=3BALTER TABLE gorfs.nfs_data ADD COLUMN migration_date timestamp wi= th time zone=3BALTER TABLE gorfs.nfs_data ADD CONSTRAINT nfs_data_pkey PRI= MARY KEY("file_id")=3B QUESTION:How could I create the Query?Any help would be great. Thank you! = --_985078f1-ddbe-484f-a35f-6b758f532256_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
So.. I have a Query that is taking to= o long to complete.

OLD QUERY:
 =3B SELECT
<= blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex=3B bord= er-left-width: 1px=3B border-left-color: rgb(204=2C 204=2C 204)=3B border-l= eft-style: solid=3B padding-left: 1ex=3B"> =3B file.inode_id  =3B &= nbsp=3B  =3B  =3BAS file_id=2C
=
 =3B file.parent_inode_id AS file_group=2C
 =3B file.relative_path  =3B AS= file_type=2C
 =3B fi= le.file_data  =3B  =3B  =3B AS file_binary=2C
 =3B file.node_full_path  =3BAS fi= le_name=2C
 =3B file= .last_modified  =3B AS date_created
FROM
 = =3B gorfs.nodes AS file
&= nbsp=3B INNER JOIN
 = =3B gorfs.inode_segments AS iseg ON iseg.st_ino =3D file.parent_inode_id
=
 =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B  =3B  =3B  =3B  =3B AND file.object_type= =3D 'S_IFREG'
 =3B &= nbsp=3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B &nbs= p=3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B AND ise= g.nfs_migration_date IS NULL
 =3B  =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B AND (file.last_modified <=3B
 =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B  =3B  =3B  =3B(transaction_timestamp() AT TI= ME ZONE 'UTC' - '1 months' :: INTERVAL))
 =3B  =3B  =3B  =3B  =3B  =3B  = =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B  =3B=  =3B  =3B AND iseg.st_ino_target =3D file.inode_id
LIMIT
 =3B 100=3B

We created =3Ba new temporary table to sto= re migrations=2C which may be the best option (no longer need to join new c= olumns in query).
I just need the =3Bsame output as any of the correct above one.
<= span style=3D"color: rgb(38=2C 50=2C 56)=3B font-size: 13px=3B line-height:= 16px=3B">
NEW QUERY STRUCTURE:

table: = =3Bgorfs.nfs_data:

CREATE TABLE gorfs.nfs_data
<= /div>
(
 =3B owner_id = integer NOT NULL=2C
=
 = =3B file_id integer NOT NULL=2C
 =3B migration_path "text"=2C
 =3B migration_date timestamp with time zone=2C<= /font>
 =3B CONSTRAINT nfs_data_pke= y PRIMARY KEY ("file_id")
)

INDEX:&nbs= p=3B

CREA= TE INDEX ix_nfs_data_owner_id
<= /div>
=
 =3B ON gorfs.nfs_data
 =3B USING btree
 =3B ("owner_id")
 =3B WHERE "migration_date" IS NULL=3B
<= /div>


OLD EXPLAIN ANALYZE (Using the OLD query):
COLUMNS:
ALTER TABLE gorfs.nfs_data ADD COLU= MN owner_id integer=3B
= ALTER TABLE gorfs.nfs_data ALTER COLUM= N owner_id SET NOT NULL=3B
ALTER TABLE gorfs.nfs_data ADD COL= UMN file_id integer=3B
= ALTER TABLE gorfs.nfs_data ALTER COLUM= N file_id SET NOT NULL=3B
ALTER TABLE gorfs.nfs_data ADD COLU= MN migration_path "text"=3B
ALTER TABLE gorfs.nfs_data ADD CO= LUMN migration_date timestamp with time zone=3B
ALTER TABLE g= orfs.nfs_data
 =3B ADD CONSTRAINT nfs_data_pkey PRIMARY K= EY("file_id")=3B


QUESTION:
How could = I create the Query?
Any help would be great.

Thank you!
= --_985078f1-ddbe-484f-a35f-6b758f532256_--