Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLVqL-0003OD-04 for pgsql-performance@arkaria.postgresql.org; Thu, 06 Mar 2014 10:48:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WLVqK-0003ha-2Z for pgsql-performance@arkaria.postgresql.org; Thu, 06 Mar 2014 10:48:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLVqH-0003hR-Ax for pgsql-performance@postgresql.org; Thu, 06 Mar 2014 10:47:57 +0000 Received: from flash1.cnio.es ([193.147.150.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLVqB-0007Tr-Pj for pgsql-performance@postgresql.org; Thu, 06 Mar 2014 10:47:56 +0000 Received: from flash1.cnio.es (localhost [127.0.0.1]) by flash1.cnio.es (ESMTP Server) with ESMTP id 96FA119BB2; Thu, 6 Mar 2014 11:47:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on flash1.cnio.es X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, FH_DATE_PAST_20XX,HTML_MESSAGE autolearn=no version=3.2.5 Received: from owa1.cnio.es (owa1.cnio.es [192.168.10.7]) by flash1.cnio.es (ESMTP Server) with ESMTP; Thu, 6 Mar 2014 11:47:43 +0100 (CET) Thread-Index: Ac85KYAZu8L0tObfQlGQrpzPbtuvow== Received: from [10.222.112.134] ([10.222.112.134]) by owa1.cnio.es over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 6 Mar 2014 11:47:42 +0100 Subject: Re: Query taking long time MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="Apple-Mail=_D0E97917-9D36-4BF8-80F9-1063C40322BF" Content-Transfer-Encoding: 7bit From: "acanada" In-Reply-To: Date: Thu, 6 Mar 2014 11:47:41 +0100 Cc: Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 Message-ID: <42391040-3FF8-4391-B248-ADFDBA8AB586@cnio.es> References: <3AE16087-DE09-4EE0-BDF7-F2DFC68CB6CB@cnio.es><42CEB1D5-629F-490A-A99B-2E15B60CA6D1@cnio.es><964F1009-8714-4B4C-8386-45D3D7A95738@cnio.es><6F33D2DE-AC10-4B2F-9C56-BBBC77D28BE0@cnio.es><53A07D29-68DD-4772-9738-AAA19F554B61@cnio.es> To: "Venkata Balaji Nagothi" X-Mailer: Apple Mail (2.1283) X-OriginalArrivalTime: 06 Mar 2014 10:47:42.0203 (UTC) FILETIME=[801054B0:01CF3929] X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org This is a multi-part message in MIME format. --Apple-Mail=_D0E97917-9D36-4BF8-80F9-1063C40322BF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Hi Venkata, Increasing the work_mem doesn't improve results. After raising it to = 1GB: limtox=3D> explain analyze select * from entity_compounddict2document = where name=3D'Troglitazone' order by hepval; = QUERY PLAN = =20 = --------------------------------------------------------------------------= --------------------------------------------------------------------------= -- Sort (cost=3D11083.47..11090.54 rows=3D2828 width=3D133) (actual = time=3D19679.354..19679.494 rows=3D1283 loops=3D1) Sort Key: hepval Sort Method: quicksort Memory: 238kB -> Bitmap Heap Scan on entity_compounddict2document = (cost=3D73.87..10921.34 rows=3D2828 width=3D133) (actual = time=3D93.926..19677.110 rows=3D1283 loops=3D1) Recheck Cond: ((name)::text =3D 'Troglitazone'::text) -> Bitmap Index Scan on entity_compound2document_name = (cost=3D0.00..73.16 rows=3D2828 width=3D0) (actual time=3D78.005..78.005 = rows=3D1283 loops=3D1) Index Cond: ((name)::text =3D 'Troglitazone'::text) Total runtime: 19679.680 ms There are not temp files in the data_directory... I have set to 1MB = log_temp_files and did this query again but there's nothing related to = tmp files in it... I cannot see "temp_files" column in pg_stat_database view (using 8.3 = version) :-( Thanks for your help. Regards, Andr=E9s El Mar 6, 2014, a las 2:36 AM, Venkata Balaji Nagothi escribi=F3: > Hi Andres, >=20 > Sorting cost is high !! >=20 > This query must be going for a disk sort, do you see temp files = getting created in pg_stat_tmp directory in the data directory ? >=20 > Or you can enable "log_temp_files" to probably 1 MB or so. This will = log the information about temp files in the log file in pg_log = directory. >=20 > Or you can see "temp_files" column in pg_stat_database view before and = after the execution of the query. >=20 > How much work_mem did you give ? you can increase the work_mem to = probably 1 GB at session level and run the query. That might have = different results. >=20 > Dropping of other Indexes will not effect this query's performance. I = recommended them to be dropped to avoid maintenance and performance = over-head in future. >=20 > Venkata Balaji N >=20 > Sr. Database Administrator > Fujitsu Australia >=20 >=20 > On Wed, Mar 5, 2014 at 10:14 PM, acanada wrote: > Hi, >=20 > This are the parameters of the server: >=20 > SELECT name, current_setting(name), source > FROM pg_settings > WHERE source NOT IN ('default', 'override'); >=20 > name | current_setting | source = =20 > = ----------------------------+--------------------+---------------------- > client_encoding | UTF8 | client > DateStyle | ISO, DMY | configuration file > default_statistics_target | 100 | configuration file > default_text_search_config | pg_catalog.spanish | configuration file > effective_cache_size | 7500MB | configuration file > lc_messages | es_ES.UTF-8 | configuration file > lc_monetary | es_ES.UTF-8 | configuration file > lc_numeric | C | configuration file > lc_time | es_ES.UTF-8 | configuration file > listen_addresses | * | configuration file > log_line_prefix | %t | configuration file > log_timezone | localtime | command line > maintenance_work_mem | 2000MB | configuration file > max_connections | 100 | configuration file > max_fsm_pages | 63217760 | configuration file > max_stack_depth | 2MB | environment = variable > port | 5432 | configuration file > shared_buffers | 1500MB | configuration file > ssl | on | configuration file > tcp_keepalives_count | 9 | configuration file > tcp_keepalives_idle | 7200 | configuration file > tcp_keepalives_interval | 75 | configuration file > TimeZone | localtime | command line > timezone_abbreviations | Default | command line > work_mem | 50MB | configuration file >=20 >=20 > The server has 2 processors quadcore, 10GB of RAM and data is located = in a fiber disk of 2TB. > Changing work_mem parameter seems to have no effect on the perform. >=20 > Now I have a curious situation. I created a new table, the one we are = query against. This table, entity_compounddict2document has less rows = aprox. 50M vs. the original table entity2document2 that has 94M rows. > Well, after dropping indexes not already in use, both tables have the = same performance with this query...=20 >=20 >=20 > explain analyze select * from entity_compounddict2document where = name=3D'Troglitazone' order by hepval; > = QUERY PLAN = =20 > = --------------------------------------------------------------------------= --------------------------------------------------------------------------= -- > Sort (cost=3D11083.47..11090.54 rows=3D2828 width=3D133) (actual = time=3D19708.019..19708.136 rows=3D1283 loops=3D1) > Sort Key: hepval > Sort Method: quicksort Memory: 238kB > -> Bitmap Heap Scan on entity_compounddict2document = (cost=3D73.87..10921.34 rows=3D2828 width=3D133) (actual = time=3D44.292..19705.954 rows=3D1283 loops=3D1) > Recheck Cond: ((name)::text =3D 'Troglitazone'::text) > -> Bitmap Index Scan on entity_compound2document_name = (cost=3D0.00..73.16 rows=3D2828 width=3D0) (actual time=3D28.159..28.159 = rows=3D1283 loops=3D1) > Index Cond: ((name)::text =3D 'Troglitazone'::text) > Total runtime: 19708.275 ms > (8 rows) >=20 >=20 > explain analyze select * from entity2document2 where = name=3D'Troglitazone' order by hepval; > = QUERY PLAN = =20 > = --------------------------------------------------------------------------= -------------------------------------------------------------------- > Sort (cost=3D18237.75..18249.38 rows=3D4653 width=3D123) (actual = time=3D18945.732..18945.869 rows=3D1283 loops=3D1) > Sort Key: hepval > Sort Method: quicksort Memory: 238kB > -> Bitmap Heap Scan on entity2document2 (cost=3D117.37..17954.29 = rows=3D4653 width=3D123) (actual time=3D41.703..18943.720 rows=3D1283 = loops=3D1) > Recheck Cond: ((name)::text =3D 'Troglitazone'::text) > -> Bitmap Index Scan on entity2document2_name = (cost=3D0.00..116.20 rows=3D4653 width=3D0) (actual time=3D28.703..28.703 = rows=3D1283 loops=3D1) > Index Cond: ((name)::text =3D 'Troglitazone'::text) > Total runtime: 18945.991 ms > (8 rows) >=20 > Description of the tables are: >=20 > limtox=3D> \d+ entity_compounddict2document; > Table "public.entity_compounddict2document" > Column | Type | Modifiers | = Storage | Description=20 > = ------------------+--------------------------------+-----------+----------= +------------- > id | integer | not null | plain = |=20 > document_id | integer | | plain = |=20 > name | character varying(255) | | = extended |=20 > qualifier | character varying(255) | | = extended |=20 > tagMethod | character varying(255) | | = extended |=20 > created | timestamp(0) without time zone | | plain = |=20 > updated | timestamp(0) without time zone | | plain = |=20 > curation | integer | | plain = |=20 > hepval | double precision | | plain = |=20 > cardval | double precision | | plain = |=20 > nephval | double precision | | plain = |=20 > phosval | double precision | | plain = |=20 > patternCount | double precision | | plain = |=20 > ruleScore | double precision | | plain = |=20 > hepTermNormScore | double precision | | plain = |=20 > hepTermVarScore | double precision | | plain = |=20 > Indexes: > "entity_compounddict2document_pkey" PRIMARY KEY, btree (id) > "entity_compound2document_name" btree (name) > "entity_compound2document_nephval" btree (nephval) > Has OIDs: no >=20 >=20 > limtox=3D> \d+ entity2document2; > Table "public.entity2document2" > Column | Type | Modifiers | = Storage | Description=20 > = ------------------+--------------------------------+-----------+----------= +------------- > id | integer | not null | plain = |=20 > document_id | integer | | plain = |=20 > name | character varying(255) | | = extended |=20 > qualifier | character varying(255) | | = extended |=20 > tagMethod | character varying(255) | | = extended |=20 > created | timestamp(0) without time zone | | plain = |=20 > updated | timestamp(0) without time zone | | plain = |=20 > curation | integer | | plain = |=20 > hepval | double precision | | plain = |=20 > cardval | double precision | | plain = |=20 > nephval | double precision | | plain = |=20 > phosval | double precision | | plain = |=20 > patternCount | double precision | | plain = |=20 > ruleScore | double precision | | plain = |=20 > hepTermNormScore | double precision | | plain = |=20 > hepTermVarScore | double precision | | plain = |=20 > Indexes: > "entity2document2_pkey" PRIMARY KEY, btree (id) > "entity2document2_hepval_index" btree (hepval) > "entity2document2_name" btree (name) > "entity2document2_qualifier_name_hepval" btree (qualifier, name) > "entity2document_qualifier_index" btree (qualifier) > Has OIDs: no >=20 >=20 >=20 > I really appreciate your help!! >=20 > Regards, > Andr=E9s >=20 >=20 >=20 >=20 > El Mar 5, 2014, a las 12:35 AM, Venkata Balaji Nagothi escribi=F3: >=20 >> After looking at the distinct values, yes the composite Index on = "name" and "hepval" is not recommended. That would worsen - its = expected. >>=20 >> We need to look for other possible work around. Please drop off the = above Index. Let me see if i can drill further into this. >>=20 >> Meanwhile - can you help us know the memory parameters (work_mem, = temp_buffers etc) set ? >>=20 >> Do you have any other processes effecting this query's performance ? >>=20 >> Any info about your Disk, RAM, CPU would also help. >>=20 >> Regards, >> Venkata Balaji N >>=20 >> Fujitsu Australia >>=20 >>=20 >>=20 >>=20 >> Venkata Balaji N >>=20 >> Sr. Database Administrator >> Fujitsu Australia >>=20 >>=20 >> On Tue, Mar 4, 2014 at 10:23 PM, acanada wrote: >> Hello, >>=20 >> I don't know if this helps to figure out what is the problem but = after adding the multicolumn index on name and hepval, the performance = is even worse (=BF?). Ten times worse... >>=20 >> explain analyze select * from (select * from = entity_compounddict2document where name=3D'progesterone') as a order by = a.hepval; >> = QUERY PLAN = =20 >> = --------------------------------------------------------------------------= --------------------------------------------------------------------------= --------- >> Sort (cost=3D422746.18..423143.94 rows=3D159104 width=3D133) = (actual time=3D95769.674..95797.943 rows=3D138165 loops=3D1) >> Sort Key: entity_compounddict2document.hepval >> Sort Method: quicksort Memory: 25622kB >> -> Bitmap Heap Scan on entity_compounddict2document = (cost=3D3501.01..408999.90 rows=3D159104 width=3D133) (actual = time=3D70.789..95519.258 rows=3D138165 loops=3D1) >> Recheck Cond: ((name)::text =3D 'progesterone'::text) >> -> Bitmap Index Scan on entity_compound2document_name = (cost=3D0.00..3461.23 rows=3D159104 width=3D0) (actual = time=3D35.174..35.174 rows=3D138165 loops=3D1) >> Index Cond: ((name)::text =3D 'progesterone'::text) >> Total runtime: 95811.838 ms >> (8 rows) >>=20 >> Any ideas please? >>=20 >> Thank you=20 >> Andr=E9s. >>=20 >>=20 >>=20 >> El Mar 4, 2014, a las 12:28 AM, Venkata Balaji Nagothi escribi=F3: >>=20 >>> On Mon, Mar 3, 2014 at 9:17 PM, acanada wrote: >>> Hello, >>>=20 >>> Thankyou for your answer. >>> I have made more changes than a simple re-indexing recently. I have = moved the sorting field to the table in order to avoid the join clause. = Now the schema is very simple. The query only implies one table: >>>=20 >>> x=3D> \d+ entity_compounddict2document; >>> Table "public.entity_compounddict2document" >>> Column | Type | Modifiers | = Storage | Description=20 >>> = ------------------+--------------------------------+-----------+----------= +------------- >>> id | integer | not null | = plain |=20 >>> document_id | integer | | = plain |=20 >>> name | character varying(255) | | = extended |=20 >>> qualifier | character varying(255) | | = extended |=20 >>> tagMethod | character varying(255) | | = extended |=20 >>> created | timestamp(0) without time zone | | = plain |=20 >>> updated | timestamp(0) without time zone | | = plain |=20 >>> curation | integer | | = plain |=20 >>> hepval | double precision | | = plain |=20 >>> cardval | double precision | | = plain |=20 >>> nephval | double precision | | = plain |=20 >>> phosval | double precision | | = plain |=20 >>> patternCount | double precision | | = plain |=20 >>> ruleScore | double precision | | = plain |=20 >>> hepTermNormScore | double precision | | = plain |=20 >>> hepTermVarScore | double precision | | = plain |=20 >>> Indexes: >>> "entity_compounddict2document_pkey" PRIMARY KEY, btree (id) >>> "entity_compound2document_cardval" btree (cardval) >>> "entity_compound2document_heptermnormscore" btree = ("hepTermNormScore") >>> "entity_compound2document_heptermvarscore" btree = ("hepTermVarScore") >>> "entity_compound2document_hepval" btree (hepval) >>> "entity_compound2document_name" btree (name) >>> "entity_compound2document_nephval" btree (nephval) >>> "entity_compound2document_patterncount" btree ("patternCount") >>> "entity_compound2document_phosval" btree (phosval) >>> "entity_compound2document_rulescore" btree ("ruleScore") >>> Has OIDs: no >>>=20 >>> tablename | indexname = | num_rows | table_size | = index_size | unique | number_of_scans | tuples_read | tuples_fetched=20 >>> entity_compounddict2document | entity_compound2document_cardval = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>> entity_compounddict2document | = entity_compound2document_heptermnormscore | 5.42452e+07 | 6763 MB = | 1162 MB | Y | 0 | 0 | 0 >>> entity_compounddict2document | = entity_compound2document_heptermvarscore | 5.42452e+07 | 6763 MB = | 1162 MB | Y | 0 | 0 | 0 >>> entity_compounddict2document | entity_compound2document_hepval = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>> entity_compounddict2document | entity_compound2document_name = | 5.42452e+07 | 6763 MB | 1505 MB | Y | = 24 | 178680 | 0 >>> entity_compounddict2document | entity_compound2document_nephval = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>> entity_compounddict2document | = entity_compound2document_patterncount | 5.42452e+07 | 6763 MB = | 1162 MB | Y | 0 | 0 | 0 >>> entity_compounddict2document | entity_compound2document_phosval = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>> entity_compounddict2document | entity_compound2document_rulescore = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>> entity_compounddict2document | entity_compounddict2document_pkey = | 5.42452e+07 | 6763 MB | 1162 MB | Y | = 0 | 0 | 0 >>>=20 >>> The table has aprox. 54,000,000 rows >>> There are no NULLs in hepval field and pg_settings haven't changed. = I also have done "analyze" to this table. >>>=20 >>> I have simplified the query and added the last advise that you told = me: >>>=20 >>> Query:=20 >>>=20 >>> explain analyze select * from (select * from = entity_compounddict2document where name=3D'ranitidine') as a order by = a.hepval; >>> = QUERY PLAN = =20 >>> = --------------------------------------------------------------------------= --------------------------------------------------------------------------= -- >>> Sort (cost=3D11060.50..11067.55 rows=3D2822 width=3D133) (actual = time=3D32715.097..32716.488 rows=3D13512 loops=3D1) >>> Sort Key: entity_compounddict2document.hepval >>> Sort Method: quicksort Memory: 2301kB >>> -> Bitmap Heap Scan on entity_compounddict2document = (cost=3D73.82..10898.76 rows=3D2822 width=3D133) (actual = time=3D6.034..32695.483 rows=3D13512 loops=3D1) >>> Recheck Cond: ((name)::text =3D 'ranitidine'::text) >>> -> Bitmap Index Scan on entity_compound2document_name = (cost=3D0.00..73.12 rows=3D2822 width=3D0) (actual time=3D3.221..3.221 = rows=3D13512 loops=3D1) >>> Index Cond: ((name)::text =3D 'ranitidine'::text) >>> Total runtime: 32717.548 ms >>>=20 >>> Another query: >>> =09 >>> explain analyze select * from (select * from = entity_compounddict2document where name=3D'progesterone' ) as a order = by a.hepval; >>>=20 >>> QUERY PLAN = =20 >>> = --------------------------------------------------------------------------= --------------------------------------------------------------------------= -------- >>> Sort (cost=3D367879.25..368209.24 rows=3D131997 width=3D133) = (actual time=3D9262.887..9287.046 rows=3D138165 loops=3D1) >>> Sort Key: entity_compounddict2document.hepval >>> Sort Method: quicksort Memory: 25622kB >>> -> Bitmap Heap Scan on entity_compounddict2document = (cost=3D2906.93..356652.81 rows=3D131997 width=3D133) (actual = time=3D76.316..9038.485 rows=3D138165 loops=3D1) >>> Recheck Cond: ((name)::text =3D 'progesterone'::text) >>> -> Bitmap Index Scan on entity_compound2document_name = (cost=3D0.00..2873.93 rows=3D131997 width=3D0) (actual = time=3D40.913..40.913 rows=3D138165 loops=3D1) >>> Index Cond: ((name)::text =3D 'progesterone'::text) >>> Total runtime: 9296.815 ms >>>=20 >>>=20 >>> It has improved (I supose because of the lack of the join table) but = still taking a lot of time... Anything I can do?? >>>=20 >>> Any help would be very appreciated. Thank you very much. >>>=20 >>>=20 >>> Good to know performance has increased. >>>=20 >>> "entity_compounddict2document" table goes through high INSERTS ? >>>=20 >>> Can you help us know if the "helpval" column and "name" column have = high duplicate values ? "n_distinct" value from pg_stats table would = have that info.=20 >>>=20 >>> Below could be a possible workaround - >>>=20 >>> As mentioned earlier in this email, a composite Index on name and = hepval column might help. If the table does not go through lot of = INSERTS, then consider performing a CLUSTER on the table using the same = INDEX. >>>=20 >>> Other recommendations - >>>=20 >>> Please drop off all the Non-primary key Indexes which have 0 scans / = hits. This would harm the DB and the DB server whilst maintenance and = DML operations. >>>=20 >>> Regards, >>> Venkata Balaji N >>>=20 >>> Fujitsu Australia >>=20 >>=20 >>=20 >> **NOTA DE CONFIDENCIALIDAD** Este correo electr=F3nico, y en su caso = los ficheros adjuntos, pueden contener informaci=F3n protegida para el = uso exclusivo de su destinatario. Se proh=EDbe la distribuci=F3n, = reproducci=F3n o cualquier otro tipo de transmisi=F3n por parte de otra = persona que no sea el destinatario. Si usted recibe por error este = correo, se ruega comunicarlo al remitente y borrar el mensaje recibido. >>=20 >> **CONFIDENTIALITY NOTICE** This email communication and any = attachments may contain confidential and privileged information for the = sole use of the designated recipient named above. Distribution, = reproduction or any other use of this transmission by any party other = than the intended recipient is prohibited. If you are not the intended = recipient please contact the sender and delete all copies. >>=20 >>=20 >>=20 >=20 >=20 >=20 > **NOTA DE CONFIDENCIALIDAD** Este correo electr=F3nico, y en su caso = los ficheros adjuntos, pueden contener informaci=F3n protegida para el = uso exclusivo de su destinatario. Se proh=EDbe la distribuci=F3n, = reproducci=F3n o cualquier otro tipo de transmisi=F3n por parte de otra = persona que no sea el destinatario. Si usted recibe por error este = correo, se ruega comunicarlo al remitente y borrar el mensaje recibido. >=20 > **CONFIDENTIALITY NOTICE** This email communication and any = attachments may contain confidential and privileged information for the = sole use of the designated recipient named above. Distribution, = reproduction or any other use of this transmission by any party other = than the intended recipient is prohibited. If you are not the intended = recipient please contact the sender and delete all copies. >=20 >=20 >=20 =0A**NOTA DE CONFIDENCIALIDAD** Este correo electr=FFnico, y en su caso los fic= heros adjuntos, pueden contener informaci=FFn protegida para el uso exclusivo = de su destinatario. Se proh=FFbe la distribuci=FFn, reproducci=FFn o cualquier otr= o tipo de transmisi=FFn por parte de otra persona que no sea el destinatario. = Si usted recibe por error este correo, se ruega comunicarlo al remitente y b= orrar el mensaje recibido.=0A**CONFIDENTIALITY NOTICE** This email communicati= on and any attachments may contain confidential and privileged information f= or the sole use of the designated recipient named above. Distribution, repro= duction or any other use of this transmission by any party other than the in= tended recipient is prohibited. If you are not the intended recipient please= contact the sender and delete all copies.=0A=0A --Apple-Mail=_D0E97917-9D36-4BF8-80F9-1063C40322BF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="iso-8859-1" Hi = Venkata,

Increasing the work_mem doesn't improve = results. After raising it to = 1GB:

limtox=3D> explain analyze select = * from entity_compounddict2document  where name=3D'Troglitazone' = order by hepval;
            =                     =                     =                   QUERY = PLAN                   =                     =                     =           =  
---------------------------------------------------------= --------------------------------------------------------------------------= -------------------
 Sort  (cost=3D11083.47..11090.54 = rows=3D2828 width=3D133) (actual time=3D19679.354..19679.494 rows=3D1283 = loops=3D1)
   Sort Key: hepval
  =  Sort Method:  quicksort  Memory: 238kB
  =  ->  Bitmap Heap Scan on entity_compounddict2document =  (cost=3D73.87..10921.34 rows=3D2828 width=3D133) (actual = time=3D93.926..19677.110 rows=3D1283 loops=3D1)
    =      Recheck Cond: ((name)::text =3D = 'Troglitazone'::text)
         -> =  Bitmap Index Scan on entity_compound2document_name =  (cost=3D0.00..73.16 rows=3D2828 width=3D0) (actual = time=3D78.005..78.005 rows=3D1283 loops=3D1)
    =            Index Cond: ((name)::text =3D = 'Troglitazone'::text)
 Total runtime: 19679.680 = ms

There are not temp files in the = data_directory... I have set to 1MB log_temp_files and did this query = again but there's nothing related to tmp files in = it...

I cannot see  "temp_files" column in = pg_stat_database view (using 8.3 version) =  :-(


Thanks for your help. = Regards,

Andr=E9s


El Mar 6, 2014, a las 2:36 AM, Venkata Balaji = Nagothi escribi=F3:

Hi = Andres,

Sorting cost is high = !!

This query must be going for a disk sort, = do you see temp files getting created in pg_stat_tmp directory in the = data directory ?

Or you can enable "log_temp_files" to probably 1 MB = or so. This will log the information about temp files in the log file in = pg_log directory.

Or you can see "temp_files" = column in pg_stat_database view before and after the execution of the = query.

How much work_mem did you give ? you can increase = the work_mem to probably 1 GB at session level and run the query. That = might have different results.

Dropping of other = Indexes will not effect this query's performance. I recommended them to = be dropped to avoid maintenance and performance over-head in = future.

Venkata Balaji N

Sr. Database = Administrator
Fujitsu Australia


On Wed, Mar 5, 2014 at 10:14 PM, = acanada <acanada@cnio.es> wrote:
Hi,

This are the = parameters of the = server:

 SELECT name, = current_setting(name), source
  FROM = pg_settings
  WHERE source NOT IN ('default', = 'override');

          =   name            | =  current_setting   |        source   =     =  
----------------------------+--------------------+-------= ---------------
 client_encoding            | = UTF8               | = client
 DateStyle           =        | ISO, DMY           = | configuration file
 default_statistics_target =  | 100                | = configuration file
 default_text_search_config | pg_catalog.spanish | = configuration file
 effective_cache_size     =   | 7500MB             | = configuration file
 lc_messages       =          | es_ES.UTF-8       =  | configuration file
 lc_monetary               =  | es_ES.UTF-8        | configuration = file
 lc_numeric           =       | C             =      | configuration file
 lc_time   =                  | = es_ES.UTF-8        | configuration file
 listen_addresses           | * =                  | = configuration file
 log_line_prefix       =      | %t             =     | configuration file
 log_timezone   =             | localtime     =      | command line
 maintenance_work_mem       | 2000MB   =           | configuration = file
 max_connections           =  | 100                | = configuration file
 max_fsm_pages       =        | 63217760           = | configuration file
 max_stack_depth            | = 2MB                | environment = variable
 port             =           | 5432         =       | configuration file
 shared_buffers =             | 1500MB       =       | configuration file
 ssl                 =        | on           =       | configuration = file
 tcp_keepalives_count       | 9 =                  | = configuration file
 tcp_keepalives_idle     =    | 7200               | = configuration file
 tcp_keepalives_interval    | 75     =             | configuration = file
 TimeZone             =       | localtime          | = command line
 timezone_abbreviations     | = Default            | command line
 work_mem               =     | 50MB               | = configuration = file


The server has = 2 processors quadcore, 10GB of RAM and data is located in a fiber disk = of 2TB.
Changing work_mem parameter seems to have no effect on the = perform.

Now I have a curious situation. I = created a new table, the one we are query against. This table, = entity_compounddict2document has less rows aprox. 50M vs. the original = table entity2document2 that has 94M rows.
Well, after dropping indexes not already in use, both tables have = the same performance with this = query... 


 explain = analyze select * from entity_compounddict2document  where = name=3D'Troglitazone' order by hepval;
                  =                     =                     =             QUERY PLAN     =                     =                     =                     =     =  
---------------------------------------------------------= --------------------------------------------------------------------------= -------------------
 Sort  (cost=3D11083.47..11090.54 rows=3D2828 width=3D133) = (actual time=3D19708.019..19708.136 rows=3D1283 = loops=3D1)
   Sort Key: hepval
  =  Sort Method:  quicksort  Memory: 238kB
  =  ->  Bitmap Heap Scan on entity_compounddict2document =  (cost=3D73.87..10921.34 rows=3D2828 width=3D133) (actual = time=3D44.292..19705.954 rows=3D1283 loops=3D1)
         Recheck Cond: ((name)::text =3D = 'Troglitazone'::text)
         -> =  Bitmap Index Scan on entity_compound2document_name =  (cost=3D0.00..73.16 rows=3D2828 width=3D0) (actual time=3D28.159..28.159 rows=3D1283 loops=3D1)
               Index Cond: = ((name)::text =3D 'Troglitazone'::text)
 Total runtime: = 19708.275 ms
(8 = rows)


explain analyze select * = from entity2document2  where name=3D'Troglitazone' order by = hepval;
                  =                     =                     =         QUERY PLAN         =                     =                     =                 =  
---------------------------------------------------------= --------------------------------------------------------------------------= -----------
 Sort  (cost=3D18237.75..18249.38 rows=3D4653 width=3D123) = (actual time=3D18945.732..18945.869 rows=3D1283 = loops=3D1)
   Sort Key: hepval
  =  Sort Method:  quicksort  Memory: 238kB
  =  ->  Bitmap Heap Scan on entity2document2 =  (cost=3D117.37..17954.29 rows=3D4653 width=3D123) (actual = time=3D41.703..18943.720 rows=3D1283 loops=3D1)
         Recheck Cond: ((name)::text =3D = 'Troglitazone'::text)
         -> =  Bitmap Index Scan on entity2document2_name =  (cost=3D0.00..116.20 rows=3D4653 width=3D0) (actual = time=3D28.703..28.703 rows=3D1283 loops=3D1)
               Index Cond: = ((name)::text =3D 'Troglitazone'::text)
 Total runtime: = 18945.991 ms
(8 = rows)

Description of the tables = are:

limtox=3D> \d+ = entity_compounddict2document;
        =               Table = "public.entity_compounddict2document"
      = Column      |             =  Type              | Modifiers | = Storage  | Description 
=
------------------+--------------------------------+-----------+-----= -----+-------------
 id         =       | integer             =            | not null  | plain   =  | 
 document_id      | integer =                     =    |           | plain   =  | 
 name             | character = varying(255)         |         =   | extended | 
 qualifier       =  | character varying(255)         |   =         | extended | 
 tagMethod =        | character varying(255)       =   |           | extended | 
 created          | timestamp(0) = without time zone |           | plain   =  | 
 updated         =  | timestamp(0) without time zone |         =   | plain    | 
 curation   =       | integer             =            |         =   | plain    | 
 hepval           | double precision =               |       =     | plain    | 
 cardval =          | double precision     =           |           = | plain    | 
 nephval     =      | double precision         =       |           | plain   =  | 
 phosval          | double precision =               |       =     | plain    | 
 patternCount =     | double precision           =     |           | plain   =  | 
 ruleScore        | = double precision               | =           | plain    | 
 hepTermNormScore | double precision       =         |           | plain =    | 
 hepTermVarScore  | double = precision               |   =         | plain   =  | 
Indexes:
    = "entity_compounddict2document_pkey" PRIMARY KEY, btree (id)
    "entity_compound2document_name" btree = (name)
    "entity_compound2document_nephval" btree = (nephval)
Has OIDs: = no


limtox=3D> \d+ entity2document2;
  =                     =       Table = "public.entity2document2"
      Column =      |             =  Type              | Modifiers | = Storage  | Description 
=
------------------+--------------------------------+-----------+-----= -----+-------------
 id         =       | integer             =            | not null  | plain   =  | 
 document_id      | integer =                     =    |           | plain   =  | 
 name             | character = varying(255)         |         =   | extended | 
 qualifier       =  | character varying(255)         |   =         | extended | 
 tagMethod =        | character varying(255)       =   |           | extended | 
 created          | timestamp(0) = without time zone |           | plain   =  | 
 updated         =  | timestamp(0) without time zone |         =   | plain    | 
 curation   =       | integer             =            |         =   | plain    | 
 hepval           | double precision =               |       =     | plain    | 
 cardval =          | double precision     =           |           = | plain    | 
 nephval     =      | double precision         =       |           | plain   =  | 
 phosval          | double precision =               |       =     | plain    | 
 patternCount =     | double precision           =     |           | plain   =  | 
 ruleScore        | = double precision               | =           | plain    | 
 hepTermNormScore | double precision       =         |           | plain =    | 
 hepTermVarScore  | double = precision               |   =         | plain   =  | 
Indexes:
    = "entity2document2_pkey" PRIMARY KEY, btree (id)
    "entity2document2_hepval_index" btree = (hepval)
    "entity2document2_name" btree = (name)
    "entity2document2_qualifier_name_hepval" = btree (qualifier, name)
    "entity2document_qualifier_index" btree = (qualifier)
Has OIDs: = no



I really = appreciate your help!!

Regards,
=
Andr=E9s




<= div>
El Mar 5, 2014, a las 12:35 AM, Venkata Balaji Nagothi = escribi=F3:

After looking at the distinct values, yes the composite = Index on "name" and "hepval" is not recommended. That would worsen - its = expected.

We need to look for other possible work around. Please = drop off the above Index. Let me see if i can drill further into = this.

Meanwhile - can you help us know the memory = parameters (work_mem, temp_buffers etc) set = ?

Do you have any other processes effecting = this query's performance ?

Any info about your Disk, RAM, CPU would also = help.

Regards,
Venkata Balaji = N

Fujitsu = Australia




Venkata Balaji = N

Sr. Database Administrator
Fujitsu = Australia


On Tue, Mar 4, 2014 at 10:23 PM, = acanada <acanada@cnio.es> wrote:
Hello,

I don't = know if this helps to figure out what is the problem but after adding = the multicolumn index on name and hepval, the performance is even worse = (=BF?).  Ten times worse...

explain analyze select * from (select * = from entity_compounddict2document  where name=3D'progesterone') as = a order by a.hepval;
            =                     =                     =                     =  QUERY PLAN                 =                     =                     =                  
=
---------------------------------------------------------------= --------------------------------------------------------------------------= --------------------
 Sort =  (cost=3D422746.18..423143.94 rows=3D159104 width=3D133) (actual = time=3D95769.674..95797.943 rows=3D138165 loops=3D1)
   Sort Key: = entity_compounddict2document.hepval
   Sort Method: =  quicksort  Memory: 25622kB
   -> =  Bitmap Heap Scan on entity_compounddict2document =  (cost=3D3501.01..408999.90 rows=3D159104 width=3D133) (actual = time=3D70.789..95519.258 rows=3D138165 loops=3D1)
         Recheck Cond: ((name)::text = =3D 'progesterone'::text)
        =  ->  Bitmap Index Scan on entity_compound2document_name =  (cost=3D0.00..3461.23 rows=3D159104 width=3D0) (actual time=3D35.174..35.174 rows=3D138165 loops=3D1)
               Index = Cond: ((name)::text =3D = 'progesterone'::text)
 Total runtime: 95811.838 = ms
(8 rows)

Any ideas = please?

Thank = you 
Andr=E9s.



=
El Mar 4, 2014, a las 12:28 AM, Venkata Balaji Nagothi = escribi=F3:

=
On Mon, Mar 3, 2014 at = 9:17 PM, acanada <acanada@cnio.es> wrote:
Hello,

Thankyou for = your answer.
I have made more changes than a simple re-indexing recently. I have = moved the sorting field to the table in order to avoid the join clause. = Now the schema is very simple. The query only implies one = table:

x=3D> \d+ entity_compounddict2document;
  =                     = Table "public.entity_compounddict2document"
    =   Column      |           =    Type              | = Modifiers | Storage  | Description 
=
------------------+--------------------------------+-----------+-----= -----+-------------
 id         =       | integer             =            | not null  | plain   =  | 
 document_id      | = integer                   =      |           | plain   =  | 
 name             | character = varying(255)         |         =   | extended | 
 qualifier       =  | character varying(255)         |   =         | extended | 
 tagMethod =        | character varying(255)       =   |           | extended | 
 created          | timestamp(0) = without time zone |           | plain   =  | 
 updated         =  | timestamp(0) without time zone |         =   | plain    | 
 curation   =       | integer             =            |         =   | plain    | 
 hepval           | double = precision               |   =         | plain   =  | 
 cardval         =  | double precision             =   |           | plain   =  | 
 nephval         =  | double precision             =   |           | plain   =  | 
 phosval          | double precision =               |       =     | plain    | 
 patternCount =     | double precision           =     |           | plain   =  | 
 ruleScore        | = double precision               | =           | plain    | 
 hepTermNormScore | double precision       =         |           | plain =    | 
 hepTermVarScore  | double = precision               |   =         | plain   =  | 
Indexes:
    = "entity_compounddict2document_pkey" PRIMARY KEY, btree (id)
    "entity_compound2document_cardval" btree = (cardval)
    = "entity_compound2document_heptermnormscore" btree = ("hepTermNormScore")
    = "entity_compound2document_heptermvarscore" btree = ("hepTermVarScore")
    "entity_compound2document_hepval" btree = (hepval)
    "entity_compound2document_name" btree = (name)
    "entity_compound2document_nephval" btree = (nephval)
    "entity_compound2document_patterncount" btree = ("patternCount")
    = "entity_compound2document_phosval" btree (phosval)
  =   "entity_compound2document_rulescore" btree ("ruleScore")
Has OIDs: no

    =        tablename           =  |                   = indexname                   =                     =        |  num_rows    | table_size =  | index_size | unique | number_of_scans | tuples_read | = tuples_fetched 
 entity_compounddict2document   | = entity_compound2document_cardval           =     | 5.42452e+07 | 6763 MB    | 1162 MB   =  | Y      |           =     0 |           0 |     =         =  0
 entity_compounddict2document   | = entity_compound2document_heptermnormscore      | = 5.42452e+07 | 6763 MB    | 1162 MB    | Y   =    |               0 | =           0 |         =      0
 entity_compounddict2document   | = entity_compound2document_heptermvarscore       | = 5.42452e+07 | 6763 MB    | 1162 MB    | Y   =    |               0 | =           0 |         =      0
 entity_compounddict2document =   | entity_compound2document_hepval         =        | 5.42452e+07 | 6763 MB    | 1162 = MB    | Y      |         =       0 |           0 |   =            0
 entity_compounddict2document   | = entity_compound2document_name             =      | 5.42452e+07 | 6763 MB    | 1505 MB =    | Y      |         =      24 |      178680 |     =         =  0
 entity_compounddict2document   | = entity_compound2document_nephval           =     | 5.42452e+07 | 6763 MB    | 1162 MB   =  | Y      |           =     0 |           0 |     =          0
 entity_compounddict2document   | = entity_compound2document_patterncount         =  | 5.42452e+07 | 6763 MB    | 1162 MB    | Y =      |               0 = |           0 |         =      0
 entity_compounddict2document =   | entity_compound2document_phosval         =       | 5.42452e+07 | 6763 MB    | 1162 MB =    | Y      |         =       0 |           0 |   =            0
 entity_compounddict2document   | = entity_compound2document_rulescore           =   | 5.42452e+07 | 6763 MB    | 1162 MB    | Y =      |               0 = |           0 |         =      0
 entity_compounddict2document =   | entity_compounddict2document_pkey         =      | 5.42452e+07 | 6763 MB    | 1162 MB =    | Y      |         =       0 |           0 |   =            0

The table has aprox. 54,000,000 = rows
There are no NULLs in hepval field and pg_settings = haven't changed. I also have done "analyze" to this = table.

I have simplified the query and added the last advise that you told = me:

Query: 

 explain analyze select * = from (select * from entity_compounddict2document  where = name=3D'ranitidine') as a order by a.hepval;
                  =                     =                     =             QUERY PLAN     =                     =                     =                     =     =  
---------------------------------------------------------= --------------------------------------------------------------------------= -------------------
 Sort  (cost=3D11060.50..11067.55 rows=3D2822 width=3D133) = (actual time=3D32715.097..32716.488 rows=3D13512 = loops=3D1)
   Sort Key: = entity_compounddict2document.hepval
   Sort Method: =  quicksort  Memory: 2301kB
   ->  Bitmap Heap Scan on = entity_compounddict2document  (cost=3D73.82..10898.76 rows=3D2822 = width=3D133) (actual time=3D6.034..32695.483 rows=3D13512 = loops=3D1)
         Recheck Cond: = ((name)::text =3D 'ranitidine'::text)
         ->  Bitmap Index Scan on = entity_compound2document_name  (cost=3D0.00..73.12 rows=3D2822 = width=3D0) (actual time=3D3.221..3.221 rows=3D13512 = loops=3D1)
              =  Index Cond: ((name)::text =3D 'ranitidine'::text)
 Total runtime: 32717.548 ms

Another = query:
=
= explain analyze select * from (select * from = entity_compounddict2document  where name=3D'progesterone' ) as a =  order by a.hepval;

= QUERY PLAN =
--------------------------------------------------------= --------------------------------------------------------------------------= --------------------------
 Sort  (cost=3D367879.25..368209.24 rows=3D131997 = width=3D133) (actual time=3D9262.887..9287.046 rows=3D138165 = loops=3D1)
   Sort Key: = entity_compounddict2document.hepval
   Sort Method: =  quicksort  Memory: 25622kB
   ->  Bitmap Heap Scan on = entity_compounddict2document  (cost=3D2906.93..356652.81 = rows=3D131997 width=3D133) (actual time=3D76.316..9038.485 rows=3D138165 = loops=3D1)
         Recheck Cond: = ((name)::text =3D 'progesterone'::text)
         ->  Bitmap Index Scan on = entity_compound2document_name  (cost=3D0.00..2873.93 rows=3D131997 = width=3D0) (actual time=3D40.913..40.913 rows=3D138165 = loops=3D1)
              =  Index Cond: ((name)::text =3D 'progesterone'::text)
 Total runtime: 9296.815 = ms


It has improved = (I supose because of the lack of the join table) but still taking a lot = of time... Anything I can do??

Any help would be very appreciated. Thank you very = much.


Good to = know performance has = increased.

"entity_compounddict2document" = table goes through high INSERTS ?

Can you = help us know if the "helpval" column and "name" column have high = duplicate values ? "n_distinct" value from pg_stats table would have = that info. 

Below = could be a possible workaround -

As mentioned = earlier in this email, a composite Index on name and hepval column might = help. If the table does not go through lot of INSERTS, then consider = performing a CLUSTER on the table using the same INDEX.

Other = recommendations -

Please drop off all the Non-primary key Indexes = which have 0 scans / hits. This would harm the DB and the DB server = whilst maintenance and DML operations.

Regards,
Venkata = Balaji N

Fujitsu Australia



**NOTA DE CONFIDENCIALIDAD** Este correo = electr=F3nico, y en su caso los ficheros adjuntos, pueden contener = informaci=F3n protegida para el uso exclusivo de su destinatario. Se = proh=EDbe la distribuci=F3n, reproducci=F3n o cualquier otro tipo de = transmisi=F3n por parte de otra persona que no sea el destinatario. Si = usted recibe por error este correo, se ruega comunicarlo al remitente y = borrar el mensaje recibido.

**CONFIDENTIALITY NOTICE** This email communication and any = attachments may contain confidential and privileged information for the = sole use of the designated recipient named above. Distribution, = reproduction or any other use of this transmission by any party other = than the intended recipient is prohibited. If you are not the intended = recipient please contact the sender and delete all copies.





**NOTA DE = CONFIDENCIALIDAD** Este correo electr=F3nico, y en su caso los = ficheros adjuntos, pueden contener informaci=F3n protegida para el uso = exclusivo de su destinatario. Se proh=EDbe la distribuci=F3n, = reproducci=F3n o cualquier otro tipo de transmisi=F3n por parte de otra = persona que no sea el destinatario. Si usted recibe por error este = correo, se ruega comunicarlo al remitente y borrar el mensaje = recibido.

**CONFIDENTIALITY NOTICE** This email communication and any = attachments may contain confidential and privileged information for the = sole use of the designated recipient named above. Distribution, = reproduction or any other use of this transmission by any party other = than the intended recipient is prohibited. If you are not the intended = recipient please contact the sender and delete all copies.
=




=

**NOTA DE CONFIDENCIALIDAD** Este correo electrónic= o, y en su caso los ficheros adjuntos, pueden contener información pr= otegida para el uso exclusivo de su destinatario. Se prohíbe la distr= ibución, reproducción o cualquier otro tipo de transmisi&oacut= e;n por parte de otra persona que no sea el destinatario. Si usted recibe po= r error este correo, se ruega comunicarlo al remitente y borrar el mensaje r= ecibido.

**CONFIDENTIALITY NOTICE** This email communication a= nd any attachments may contain confidential and privileged information for t= he sole use of the designated recipient named above. Distribution, reproduct= ion or any other use of this transmission by any party other than the intend= ed recipient is prohibited. If you are not the intended recipient please con= tact the sender and delete all copies.
=0A=0A
= = --Apple-Mail=_D0E97917-9D36-4BF8-80F9-1063C40322BF--