Re: [GENERAL] Optimizing query?

2013-02-03 Thread Jasen Betts
On 2013-01-31, haman...@t-online.de wrote: > > Pavel Stehlule wrote: > >>> >> Hi, >>> >> >>> >> I am trying to match items from 2 tables based on a common string. >>> >> One is a big table which has one column with entries like XY123, ABC44, = >>> etc >>> >> The table has an index on that column.

Re: [GENERAL] Optimizing query?

2013-02-02 Thread Pavel Stehule
2013/2/2 Pavel Stehule : > 2013/2/2 : >> Pavel Stehule wrote: >> but maybe https://github.com/dimitri/prefix can help >> >> Hi Pavel, >> >> thanks - this works perfect. However, it does not seem to play well >> with the optimizer, so I ended up with >> >> select all candidates into

Re: [GENERAL] Optimizing query?

2013-02-02 Thread Pavel Stehule
2013/2/2 : > Pavel Stehule wrote: > >>> >>> but maybe https://github.com/dimitri/prefix can help >>> > > Hi Pavel, > > thanks - this works perfect. However, it does not seem to play well > with the optimizer, so I ended up with > > select all candidates into a temp table using prefix operator > a

Re: [GENERAL] Optimizing query?

2013-02-02 Thread hamann . w
Pavel Stehule wrote: >> >> but maybe https://github.com/dimitri/prefix can help >> Hi Pavel, thanks - this works perfect. However, it does not seem to play well with the optimizer, so I ended up with select all candidates into a temp table using prefix operator apply all other conditions by

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Pavel Stehule
Hello 2013/1/31 : > > Pavel Stehlule wrote: > >>> >> Hi, >>> >> >>> >> I am trying to match items from 2 tables based on a common string. >>> >> One is a big table which has one column with entries like XY123, ABC44, = >>> etc >>> >> The table has an index on that column. >>> >> The second table

Re: [GENERAL] Optimizing query?

2013-01-31 Thread hamann . w
Pavel Stehlule wrote: >> >> Hi, >> >> >> >> I am trying to match items from 2 tables based on a common string. >> >> One is a big table which has one column with entries like XY123, ABC44, = >> etc >> >> The table has an index on that column. >> >> The second table is, typically, much smaller >>

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Pavel Stehule
2013/1/31 Vincent Veyron : > Le jeudi 31 janvier 2013 à 11:06 +0100, Pavel Stehule a écrit : >> 2013/1/31 Vincent Veyron : >> > >> > Suppose I have a query of the form >> > >> > SELECT my_function(column_1), column_2 >> > FROM my_table >> > GROUP BY my_function(column_1) >> > ORDER BY my_function(c

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Vincent Veyron
Le jeudi 31 janvier 2013 à 11:06 +0100, Pavel Stehule a écrit : > 2013/1/31 Vincent Veyron : > > > > Suppose I have a query of the form > > > > SELECT my_function(column_1), column_2 > > FROM my_table > > GROUP BY my_function(column_1) > > ORDER BY my_function(column_1); > > > > where my_function i

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Pavel Stehule
2013/1/31 Vincent Veyron : > Le jeudi 31 janvier 2013 à 09:49 +0100, Pavel Stehule a écrit : > >> any join where result is related to some function result can be very >> slow, because estimation will be out and any repeated function >> evaluation is just expensive. >> > > Hi Pavel, > > Thank you fo

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Vincent Veyron
Le jeudi 31 janvier 2013 à 09:49 +0100, Pavel Stehule a écrit : > any join where result is related to some function result can be very > slow, because estimation will be out and any repeated function > evaluation is just expensive. > Hi Pavel, Thank you for the correction. Since we're at it, I

Re: [GENERAL] Optimizing query?

2013-01-31 Thread Pavel Stehule
2013/1/31 Vincent Veyron : > Le mercredi 30 janvier 2013 à 11:08 +, wolfg...@noten5.maas-noten.de > a écrit : >> Hi, >> >> I am trying to match items from 2 tables based on a common string. >> One is a big table which has one column with entries like XY123, ABC44, etc >> The table has an index

Re: [GENERAL] Optimizing query?

2013-01-30 Thread Vincent Veyron
Le mercredi 30 janvier 2013 à 11:08 +, wolfg...@noten5.maas-noten.de a écrit : > Hi, > > I am trying to match items from 2 tables based on a common string. > One is a big table which has one column with entries like XY123, ABC44, etc > The table has an index on that column. > The second table

[GENERAL] Optimizing query?

2013-01-30 Thread wolfgang
Hi, I am trying to match items from 2 tables based on a common string. One is a big table which has one column with entries like XY123, ABC44, etc The table has an index on that column. The second table is, typically, much smaller select from tab1, tab2 where tab1.code = tab2.code; This wo

[GENERAL] Optimizing query

2010-11-24 Thread pasman pasmański
Hello. I have a query which works a bit slow. It's runned on desktop computer: AMD Athlon X2 2GHz , Win Xp sp2, 1GB ram. Postgres 8.4.5 with some changes in config: shared_buffers = 200MB # min 128kB # (change requires restart) temp_buffers = 8MB

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
Hi Alban, On 7/3/06, Alban Hertroys <[EMAIL PROTECTED]> wrote: Alexander Farber wrote: > punbb=> select username, md5('deadbeef' || password) from users where id > = 4; > username | md5 > --+-- > Vasja| dcde745cc304742e26d62e683a9ecb0a >

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...)

2006-07-03 Thread Alban Hertroys
Alexander Farber wrote: I wonder, what is faster: fetching 2 columns - the username and the md5-result and then comparing the md5 string against the argument in my app, like here: punbb=> select username, md5('deadbeef' || password) from users where id = 4; username | md5 ---

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
Yes, you're probably right. I'm just trying to ensure, that the slow md5() function isn't called for every row in the table. If that's not the case, then the other tiny speed differences are not that important for me. Your query works too, thanks for the hint. punbb=> select username, md5('dead

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Martijn van Oosterhout
On Mon, Jul 03, 2006 at 03:13:15PM +0200, Alexander Farber wrote: > Hello, > > in my application I'm trying to authenticate users > against a table called "users". The integer column > "id" should match, but also an md5 hash of the > "password" column (salted with a string) should match. > My auth

[GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
Hello, in my application I'm trying to authenticate users against a table called "users". The integer column "id" should match, but also an md5 hash of the "password" column (salted with a string) should match. My authentication function (written in C, using libpq) should return a "username" (is

Re: [GENERAL] Optimizing query

2005-08-15 Thread Poul Møller Hansen
You're not there yet: you want what Richard said, namely I realized that it wasn't optimal for all nodes, namely those with a lot of rows. So you are absolutely right, I followed the suggestion of Richard and it works perfect. Thank you all, I learned a lesson of indexes today... Poul

Re: [GENERAL] Optimizing query

2005-08-15 Thread Tom Lane
=?ISO-8859-1?Q?Poul_M=F8ller_Hansen?= <[EMAIL PROTECTED]> writes: > explain analyze SELECT * FROM my.table WHERE node = '10' ORDER BY node, > id DESC LIMIT 1 > QUERY > PLAN

Re: [GENERAL] Optimizing query

2005-08-15 Thread Dennis Bjorklund
On Mon, 15 Aug 2005, Poul Møller Hansen wrote: > I have a problem creating a usable index for the following simple query: > SELECT * FROM my.table WHERE node = '10' ORDER BY id DESC LIMIT 1 > > id is a serial, so the query is to find the latest entry to a given node > and id is the primary key.

Re: [GENERAL] Optimizing query

2005-08-15 Thread Poul Møller Hansen
I have a problem creating a usable index for the following simple query: SELECT * FROM my.table WHERE node = '10' ORDER BY id DESC LIMIT 1 id is a serial, so the query is to find the latest entry to a given node and id is the primary key. You're not necessarily getting the latest entry, jus

Re: [GENERAL] Optimizing query

2005-08-15 Thread Richard Huxton
Poul Møller Hansen wrote: I have a problem creating a usable index for the following simple query: SELECT * FROM my.table WHERE node = '10' ORDER BY id DESC LIMIT 1 id is a serial, so the query is to find the latest entry to a given node and id is the primary key. You're not necessarily getti

[GENERAL] Optimizing query

2005-08-15 Thread Poul Møller Hansen
I have a problem creating a usable index for the following simple query: SELECT * FROM my.table WHERE node = '10' ORDER BY id DESC LIMIT 1 id is a serial, so the query is to find the latest entry to a given node and id is the primary key. The table contains around 1 million records and the query

Re: [GENERAL] Optimizing query

2003-11-19 Thread Rob Sell
idhar Daithankar Sent: Wednesday, November 19, 2003 6:23 AM To: Uros Cc: [EMAIL PROTECTED] Subject: Re: [GENERAL] Optimizing query Uros wrote: > Hello! > > I have some trouble getting good results from my query. > > here is structure > > stat_views > id| integer &g

Re: [GENERAL] Optimizing query

2003-11-19 Thread Uros
Hello Shridhar, I use Matthew's solution and it works. Query takes only half a second. I didn't know that i can index function to. Thanks Uros Wednesday, November 19, 2003, 1:23:26 PM, you wrote: SD> Uros wrote: >> Hello! >> >> I have some trouble getting good results from my query. >> >> h

Re: [GENERAL] Optimizing query

2003-11-19 Thread Shridhar Daithankar
Uros wrote: Hello! I have some trouble getting good results from my query. here is structure stat_views id| integer id_zone | integer created | timestamp I have btree index on created and also id and there is 1633832 records in that table First of all I have to manualy set seq_scan

Re: [GENERAL] Optimizing query

2003-11-19 Thread Peter Eisentraut
Uros writes: > explain SELECT count(*) as views FROM stat_views WHERE date_part('day', created) = > 18; > > QUERY PLAN > > Aggregate (cost=100101618.08..100101618.08 rows=1

Re: [GENERAL] Optimizing query

2003-11-19 Thread Matthew Lunnon
_date_part( created ) ); or add an extra date_part column to your table which pre-calculates date_part('day', created) and put an index on this.   Cheers Matthew --   - Original Message - From: Uros To: [EMAIL PROTECTED] Sent: Wednesday, November 19, 2003 10:41

[GENERAL] Optimizing query

2003-11-19 Thread Uros
Hello! I have some trouble getting good results from my query. here is structure stat_views id| integer id_zone | integer created | timestamp I have btree index on created and also id and there is 1633832 records in that table First of all I have to manualy set seq_scan to OFF be