Re: [GENERAL] Query optimization to select rows instead of too many or conditions

2015-02-21 Thread Alban Hertroys
> On 21 Feb 2015, at 12:03, Arup Rakshit wrote: > > On Saturday, February 21, 2015 12:42:03 PM Alban Hertroys wrote: >> >>> On 21 Feb 2015, at 9:34, Arup Rakshit wrote: >>> >>> Select * from Emp >>> where (attr1 = val11 and attr2 = val12 and attr3 = val13) or (attr1 = >>> val14and attr2 = v

Re: [GENERAL] Query optimization to select rows instead of too many or conditions

2015-02-21 Thread Arup Rakshit
On Saturday, February 21, 2015 12:42:03 PM Alban Hertroys wrote: > > > On 21 Feb 2015, at 9:34, Arup Rakshit wrote: > > > > Select * from Emp > > where (attr1 = val11 and attr2 = val12 and attr3 = val13) or (attr1 = > > val14and attr2 = val15 and attr3 = val16); > > > > Now suppose I got (x1,

Re: [GENERAL] Query optimization to select rows instead of too many or conditions

2015-02-21 Thread Alban Hertroys
> On 21 Feb 2015, at 9:34, Arup Rakshit wrote: > > Select * from Emp > where (attr1 = val11 and attr2 = val12 and attr3 = val13) or (attr1 = > val14and attr2 = val15 and attr3 = val16); > > Now suppose I got (x1, x2, x3) and (y1, y2, y3). Then I need to rewrite my > query as : > > Select *

[GENERAL] Query optimization to select rows instead of too many or conditions

2015-02-21 Thread Arup Rakshit
Hi, Suppose I want to select the rows from a table, say Emp, as below : Select * from Emp where (attr1 = val11 and attr2 = val12 and attr3 = val13) or (attr1 = val14and attr2 = val15 and attr3 = val16); Now suppose I got (x1, x2, x3) and (y1, y2, y3). Then I need to rewrite my query as : Sel

Re: [GENERAL] Query optimization

2014-10-29 Thread Jorge Arevalo
On Wed, Oct 29, 2014 at 8:47 PM, David Johnston wrote: > On Wed, Oct 29, 2014 at 12:14 PM, Jorge Arevalo > wrote: > >> >> SELECT value1,value2,value3,value4, value5, hstore(ARRAY['field9', >> 'field10', 'field11', 'field12', 'field13', 'field14'], ARRAY[field9, >> field10, field11, field12, fiel

Re: [GENERAL] Query optimization

2014-10-29 Thread David Johnston
On Wed, Oct 29, 2014 at 12:14 PM, Jorge Arevalo wrote: > > SELECT value1,value2,value3,value4, value5, hstore(ARRAY['field9', > 'field10', 'field11', 'field12', 'field13', 'field14'], ARRAY[field9, > field10, field11, field12, field13, field14]) as metadata, value7, (select > array((select row(f1

Re: [GENERAL] Query optimization

2014-10-29 Thread Tom Lane
Jorge Arevalo writes: >> On Wed, Oct 29, 2014 at 11:53 AM, Tom Lane wrote: >>> I'm also a bit confused as to why the planner is saying that the (SELECT >>> ARRAY(...)) bit is an InitPlan and not a SubPlan. That implies that >>> "field7" in the innermost WHERE clause is not a reference to table1

Re: [GENERAL] Query optimization

2014-10-29 Thread Jorge Arevalo
On Wed, Oct 29, 2014 at 8:05 PM, David Johnston wrote: > On Wed, Oct 29, 2014 at 11:53 AM, Tom Lane wrote: > >> Jorge Arevalo writes: >> >> > This is the result of EXPLAIN ANALYZE >> >> >QUERY >> > PLAN >> > >>

Re: [GENERAL] Query optimization

2014-10-29 Thread David Johnston
On Wed, Oct 29, 2014 at 11:53 AM, Tom Lane wrote: > Jorge Arevalo writes: > > > This is the result of EXPLAIN ANALYZE > > >QUERY > > PLAN > > >

Re: [GENERAL] Query optimization

2014-10-29 Thread Tom Lane
Jorge Arevalo writes: > SELECT value1,value2,value3,value4, > value5, hstore(ARRAY['field9', 'field10', 'field11', 'field12', 'field13', > 'field14'], ARRAY[field9, field10, field11, field12, field13, field14) as > metadata, value7, (select array((select row(f1, f2) from table2 p where > p.f3 = fi

Re: [GENERAL] Query optimization

2014-10-29 Thread David Johnston
List preference is to inline post or, at worse, bottom post. Please do not top post. On Wed, Oct 29, 2014 at 11:06 AM, Jorge Arevalo wrote: > Hello David, many thanks for your responses, > > Sorry for not providing the content of the fill_table3_function, but it > just executes 3 insert queries

Re: [GENERAL] Query optimization

2014-10-29 Thread Jorge Arevalo
Hello David, many thanks for your responses, Sorry for not providing the content of the fill_table3_function, but it just executes 3 insert queries in 3 different tables. And I've checked the time consuming operation is in this query (by the way, there was a little mistake in the name of the field

Re: [GENERAL] Query optimization

2014-10-28 Thread David G Johnston
Jorge Arévalo-2 wrote > (SELECT value1,value2,value3,value4,value5, hstore(ARRAY['field9', > 'field10', 'field11', 'field12', 'field13', 'field14'], ARRAY[field9, > field10, field11, field12, field13, field14) as metadata, value7, (select > array((select row(f1, f2) from table2 p where p.field7 = f

Re: [GENERAL] Query optimization

2014-10-28 Thread David G Johnston
Jorge Arévalo-2 wrote > So, I first generate a common table records_to_insert, using data from > table1 and table2, and then call a function fill_table3_function, in order > to insert the values into table3 (I do more things apart from insert, > that's reason to call a function instead of just rais

[GENERAL] Query optimization

2014-10-28 Thread Jorge Arevalo
Hello, I'm trying to optimize a query that takes too much time. This is what I have table1(field1, field2... field14): contains about 8.5 million rows table2(f1, f2, f3): contains about 2.5 million rows table3: is empty, and must be filled with data coming from table1 and table2 To fill table3,

Re: [GENERAL] Query optimization

2012-04-13 Thread Sergey Konoplev
Hi, On Wed, Apr 11, 2012 at 2:28 PM, wrote: >  I'm looking for materials about query optimization in PostgreSQL. I read > documentation but it doesnt contain much information. Can you recommend a > good book or website when i could learn something about this? I think you can find some good in

[GENERAL] Query optimization

2012-04-11 Thread nissyre
Hi, I'm looking for materials about query optimization in PostgreSQL. I read documentation but it doesnt contain much information. Can you recommend a good book or website when i could learn something about this? thanks in advance for your help -- Sent via pgsql-general mailing list (p

Re: [GENERAL] query optimization

2008-07-18 Thread Kevin Duffy
ot;Index Cond: ($0 = securitytypekey)" So this proves it is using the index. But I think the issue is in the interaction between the numbers of rows returned from positions_gsco and security. kd -Original Message- From: Klint Gore [mailto:[EMAIL PROTECTED] Sent: Thurs

Re: [GENERAL] query optimization

2008-07-17 Thread Klint Gore
Kevin Duffy wrote: So here are the questions for the PSQL gurus: Is getsectypekey(‘CFD’) executing for every join (or possible join) between positions_gsco and security? Causing a scan of security for every possible join. Does ‘ (select getsectypekey('CFD') ) ‘ cause the getsectype() funct

Re: [GENERAL] query optimization

2008-07-17 Thread Scott Marlowe
What does the output of explain select sec.* ... have to say? -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

[GENERAL] query optimization

2008-07-17 Thread Kevin Duffy
Hello: This posting is a follow up to this posting from July 15th. http://archives.postgresql.org/pgsql-general/2008-07/msg00569.php Given the following select statement select sec.* from security sec , positions_gsco where positions_gsco.securitykey is NULL and u

[GENERAL] query optimization

2008-07-15 Thread Kevin Duffy
Hello: I need your kind assistance to debug an optimization issue. The following two select statements in my book are almost identical. One does a lookup for security type 'CFD' and the other does the same lookup except for security 'OP'. When run with 'CFD' the query never returns. Wh

Re: [GENERAL] Query optimization (select single record and join)

2007-06-29 Thread Richard Huxton
Orest Kozyar wrote: What I am wondering is whether the database first eliminate all rows in tableA that don't meet the criteria before performing the join, or does it perform the join first then eliminate all records that don't meet the criteria? If you use "EXPLAIN SELECT ..." then PostgreSQL

[GENERAL] Query optimization (select single record and join)

2007-06-29 Thread Orest Kozyar
I have the following sql: CREATE OR REPLACE FUNCTION foo (in x integer) RETURNS float AS $$ SELECT max(tableB.columnC) FROM tableA inner join tableB on (tableA.columnA = tableB.columnB) WHERE tableA.columbA = x ... (additional code to select

Re: [GENERAL] Query optimization problem

2007-02-03 Thread Dave Page
> --- Original Message --- > From: Peter <[EMAIL PROTECTED]> > To: pgsql-general@postgresql.org > Sent: 03/02/07, 10:58:08 > Subject: Re: [GENERAL] Query optimization problem > > >>> Try SELECT count(*) FROM ... instead and see if the times are clos

Re: [GENERAL] Query optimization problem

2007-02-03 Thread Peter
Try SELECT count(*) FROM ... instead and see if the times are closer. Correct. That executes in 300ms flat: So your problem is data transfer, not the query per se. Well, based on PgAdmin times I suspected some sort of heavy 'data preparation before it's sent out' overhead How old a pgAdm

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Tom Lane
Peter <[EMAIL PROTECTED]> writes: >> Try SELECT count(*) FROM ... instead and see if the times are closer. > Correct. That executes in 300ms flat: So your problem is data transfer, not the query per se. How old a pgAdmin are you using? regards, tom lane

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Peter
>> I'm not sure if I'm heading up the right alley - seems too simple!, but here is my issue. >> >> I have about 3000 records in 'mytable', and simple > >Number of rows is not the most important thing here - the number of >occupied disc pages is (you can have a lot of small rows or a small >nub

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Peter
Query returned successfully with no result in 600 ms. Why SELECT takes 3+ second to execute? Is it something to do with my Postgres server optimization, or PgAdmin does not show correct data retrieval runtime (leaks over into query runtime or something)? Data transfer and display time usually

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 02/02/07 07:22, Richard Huxton wrote: > Peter wrote: >> >> Query returned successfully with no result in 600 ms. >> >> Why SELECT takes 3+ second to execute? Is it something to do with my >> Postgres server optimization, or PgAdmin does not show cor

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Dave Page
Richard Huxton wrote: Peter wrote: Query returned successfully with no result in 600 ms. Why SELECT takes 3+ second to execute? Is it something to do with my Postgres server optimization, or PgAdmin does not show correct data retrieval runtime (leaks over into query runtime or something)?

Re: [GENERAL] Query optimization problem

2007-02-02 Thread Richard Huxton
Peter wrote: Query returned successfully with no result in 600 ms. Why SELECT takes 3+ second to execute? Is it something to do with my Postgres server optimization, or PgAdmin does not show correct data retrieval runtime (leaks over into query runtime or something)? Data transfer and displ

[GENERAL] Query optimization problem

2007-02-02 Thread Peter
I'm not sure if I'm heading up the right alley - seems too simple!, but here is my issue. I have about 3000 records in 'mytable', and simple select * from mytable where x=1 is timed as: Total query runtime: 2933 ms. Data retrieval runtime: 791 ms. EXPLAIN says it's Seq Scan, but the actual f

[GENERAL] query optimization with UDFs

2006-10-09 Thread jungmin shin
      Hello  Everybody,   I have a question about optimization of queries which includes UDFs. Does anybody know what the Postgres does for optimizing the queries with UDFs? Does the Postgres query optimizer do anything special with UDFs?   Thanks, Jungmin Shin

Re: [GENERAL] Query optimization and indexes

2006-08-19 Thread Tom Lane
Gregory Stark <[EMAIL PROTECTED]> writes: > Tom Lane <[EMAIL PROTECTED]> writes: >> only the a = 5 clause would be used with the index. As of 8.1 it will >> consider using nonconsecutive index columns > Really? Is this the "skip scan" plan people were pining for? No, there's no skip scan, it jus

Re: [GENERAL] Query optimization and indexes

2006-08-19 Thread Gregory Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Before (if memory serves) 8.1, the planner would only consider leading > index columns as potential indexscan qualifiers. So given > > where a = 5 and c = 4; > > only the a = 5 clause would be used with the index. As of 8.1 it will > consider using

Re: [GENERAL] Query optimization and indexes

2006-08-18 Thread Tom Lane
[EMAIL PROTECTED] writes: > Suppose I have an index on 5 columns (A, B, C, D, E). > If my WHERE clause is not in that order, will the optimizer reorder > them as necessary and possible? Yes, the optimizer understands about commutativity/associativity of AND and OR ;-) > If I don't specify co

[GENERAL] Query optimization and indexes

2006-08-18 Thread felix
Suppose I have an index on 5 columns (A, B, C, D, E). If my WHERE clause is not in that order, will the optimizer reorder them as necessary and possible? WHERE A=1 AND C=3 AND B=2 AND E=5 AND D=4 Obviously it can't reorder them in all cases: WHERE A=1 AND (C=3 OR B=2) AND (E=5 OR D

Re: [GENERAL] Query optimization

2005-10-01 Thread Jim C. Nasby
On Fri, Sep 30, 2005 at 06:24:52PM -0400, Sean Davis wrote: >-> Seq Scan on u_all_est_mrna c (cost=0.00..932582.74 rows=24225174 > width=179) (actual time=17.384..302484.904 rows=24225174 loops=1) That step is where most of your time is being spent, which isn't surprising given that it's sca

[GENERAL] Query optimization

2005-09-30 Thread Sean Davis
I have a couple of very large tables that I am querying on that gives the following explain analyze output. If someone can help out with my mess, that would be great. Thanks, Sean explain analyze select e.*,c.* from u_all_est_mrna c join g_rna_acc d on c.accession=d.accession,

Re: [GENERAL] query optimization

2005-08-13 Thread marcelo Cortez
hi guys , Richad you are right!, my apologies profile data: postgres: "PostgreSQL 7.4.3 on i386-pc-linux-gnu, compiled by GCC 2.95.4" HP proliant processor: Dual Xeon 3.40 Ghz. HD:250 Gigabytes hard disk storage. responses: > Comment 4 - you apply a LIMIT without an ORDER BY. > Are

Re: [GENERAL] query optimization

2005-08-12 Thread Richard Huxton
marcelo Cortez wrote: hi guys i need advice for query optimization,take too long time. any coments are welcomed :). Comment 1 - you'll need to post the output of "EXPLAIN ANALYSE", not just EXPLAIN, otherwise people can't see how long it took. Comment 2 - you provide the definition of o

[GENERAL] query optimization

2005-08-12 Thread marcelo Cortez
hi guys i need advice for query optimization,take too long time. any coments are welcomed :). best MDC SELECT c.actuacion_car AS c_actuacion, c.comentario1 || ' ' || c.comentario2 || ' ' || c.comentario3 AS c_comentario FROM caratult AS c INNER JOIN extractt AS t1 ON

Re: [GENERAL] General query optimization howto

2005-03-13 Thread Miroslav Šulc
Peter Eisentraut wrote: Miroslav ¦ulc wrote: is there on the net any general howto on SQL query optimizations? We have recently moved our project from MySQL to PostgreSQL and are having problem with one of our queries. I doubt that there is a generic documentation on SQL optimization, beca

Re: [GENERAL] General query optimization howto

2005-03-13 Thread Miroslav Šulc
Bruce Momjian wrote: Have you read the FAQ? Yes, but I have found only some useful information saying when indexes are not used. Miroslav Šulc begin:vcard fn;quoted-printable:Miroslav =C5=A0ulc n;quoted-printable:=C5=A0ulc;Miroslav org:StartNet s.r.o. adr;quoted-printable;quoted-printable:;;Vrchl

Re: [GENERAL] General query optimization howto

2005-03-13 Thread Ragnar Hafstað
On Sun, 2005-03-13 at 02:34 +0100, Miroslav Šulc wrote: > is there on the net any general howto on SQL query optimizations? We > have recently moved our project from MySQL to PostgreSQL and are having > problem with one of our queries. The EXPLAIN command is surely useful > but I don't know how

Re: [GENERAL] General query optimization howto

2005-03-13 Thread Peter Eisentraut
Miroslav ¦ulc wrote: > is there on the net any general howto on SQL query optimizations? We > have recently moved our project from MySQL to PostgreSQL and are > having problem with one of our queries. I doubt that there is a generic documentation on SQL optimization, because this heavily depends

[GENERAL] General query optimization howto

2005-03-12 Thread Miroslav Šulc
Hi all, is there on the net any general howto on SQL query optimizations? We have recently moved our project from MySQL to PostgreSQL and are having problem with one of our queries. The EXPLAIN command is surely useful but I don't know how to read it and how to use the output to optimize the qu

Re: [GENERAL] query optimization: aggregate and distinct

2003-08-21 Thread Tom Lane
Jeff Davis <[EMAIL PROTECTED]> writes: > I had an idea about using aggregates: what if I made an aggregate function > called "first" that just returned the value in the first tuple it > encountered? You could make that work in 7.4, but not in any existing releases. The trouble is that you need