Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread David Noel
Very strange. I ran the query and it seemed slow so I rewrote it with a join instead. Using join it finished in 800ms. The query using the lateral finished in more than a minute. I guess I need to do some analysis on those queries to figure out why there was such a vast difference in performance.

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread David Noel
The FreeBSD system is running 9.3, the Windows systems are running 9.2. I am waiting on the output from the other developer. On Tue, Apr 29, 2014 at 8:46 AM, Tom Lane t...@sss.pgh.pa.us wrote: David Noel david.i.n...@gmail.com writes: Both queries are run from a Java project using the latest

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread David Noel
For 9.3, you can write that as: select p.*, s.NoOfSentences from page p, lateral (select count(*) as NoOfSentences from sentence s where s.PageURL = p.URL) s where Classification like case ... end order by PublishDate desc limit 100; Performance will be

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread Tomas Vondra
On 30 Duben 2014, 10:46, David Noel wrote: Very strange. I ran the query and it seemed slow so I rewrote it with a join instead. Using join it finished in 800ms. The query using the lateral finished in more than a minute. I guess I need to do some analysis on those queries to figure out why

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread Vik Fearing
On 04/30/2014 01:08 PM, David Noel wrote: For 9.3, you can write that as: select p.*, s.NoOfSentences from page p, lateral (select count(*) as NoOfSentences from sentence s where s.PageURL = p.URL) s where Classification like case ... end order by

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-30 Thread David Noel
There is nothing wrong with LATERALs, they just have no business being used here. Sorry for the noise. Ah. No trouble. In fact I'm glad you chimed in -- it motivated me to learn about laterals so now I know some new SQL syntax! -- Sent via pgsql-general mailing list

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Achilleas Mantzios
On 29/04/2014 09:59, David Noel wrote: The query I'm running is: select page.*, coalesce((select COUNT(*) from sentence where sentence.PageURL = page.URL group by page.URL), 0) as NoOfSentences from page WHERE Classification LIKE CASE WHEN THEN ELSE '%' END ORDER BY PublishDate DESC Offset 0

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
On 4/29/14, Achilleas Mantzios ach...@matrix.gatewaynet.com wrote: On 29/04/2014 09:59, David Noel wrote: select page.*, coalesce((select COUNT(*) from sentence where sentence.PageURL = page.URL group by page.URL), 0) as NoOfSentences from page WHERE Classification LIKE CASE WHEN THEN ELSE

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
Ahh, sorry, copied the query over incorrectly. It should read as follows: select page.*, coalesce((select COUNT(*) from sentence where sentence.PageURL = page.URL group by page.URL), 0) as NoOfSentences from page WHERE Classification LIKE CASE WHEN 'health''' THEN 'health' ELSE '%' END ORDER BY

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread John R Pierce
On 4/29/2014 12:42 AM, David Noel wrote: Ok, thanks for the heads up. It confused me, too. It's code I'm just picking up from another developer, so I don't know why it was done the way it was done. I'm not super proficient with SQL but I'll take a stab at rewriting it. wild guess says it was

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Vik Fearing
On 04/29/2014 09:44 AM, David Noel wrote: Ahh, sorry, copied the query over incorrectly. It should read as follows: select page.*, coalesce((select COUNT(*) from sentence where sentence.PageURL = page.URL group by page.URL), 0) as NoOfSentences from page WHERE Classification LIKE CASE WHEN

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
select p.*, s.NoOfSentences from page p, lateral (select count(*) as NoOfSentences from sentence s where s.PageURL = p.URL) s where Classification like case ... end order by PublishDate desc limit 100; Great. Thanks so much! Could I make it even simpler

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
Ehh, to clarify I'm referring to the lone _double_ quotation mark at the end of the condition 'health'''. I called it a single quotation mark because it was a quotation mark all by itself, but realize that could be misread. Single quotation marks are technically this: ' Sorry for the newbie spam

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Achilleas Mantzios
On 29/04/2014 12:39, David Noel wrote: Ehh, to clarify I'm referring to the lone _double_ quotation mark at the end of the condition 'health'''. I called it a single quotation mark because it was a quotation mark all by itself, but realize that could be misread. Single quotation marks are

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
'health''' (if that is what you have) means a boolean expression that compares the literal 'health' with the empty literal '' which is of course always false. Ah. Gotcha. Thanks. I didn't know you could use a single double quotation mark in a query -- I thought like in most languages that you

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Achilleas Mantzios
On 29/04/2014 12:54, David Noel wrote: 'health''' (if that is what you have) means a boolean expression that compares the literal 'health' with the empty literal '' which is of course always false. Ah. Gotcha. Thanks. I didn't know you could use a single double quotation mark in a query -- I

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Tomas Vondra
On 29 Duben 2014, 8:59, David Noel wrote: The query I'm running is: select page.*, coalesce((select COUNT(*) from sentence where sentence.PageURL = page.URL group by page.URL), 0) as NoOfSentences from page WHERE Classification LIKE CASE WHEN THEN ELSE '%' END ORDER BY PublishDate DESC

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
But there are two of them : ' and ' makes ''. If you use only one psql/parser will complain. Ha! Wow. That one totally flew by me. It's not a double quotation mark (one character), it's a double _single_ quotation mark (two characters). Yeah, that makes complete sense. Wow. Can't believe I

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread David Noel
Is both server/client running on FreeBSD or Windows, or are you switching only part of the stack? When I run it it's all FreeBSD. When the other developer working on it runs it it's all Windows. It shouldn't get stuck. It might be slower on some platforms, but it shouldn't really get stuck,

Re: [GENERAL] SQL query runs fine on one platform (FreeBSD), but hangs on another (Windows)

2014-04-29 Thread Tom Lane
David Noel david.i.n...@gmail.com writes: Both queries are run from a Java project using the latest JDBC driver. The PostgreSQL Server versions it's being run on are 9.2 and 9.3. The query executes and returns just fine when run on a FreeBSD-based platform, but executes forever when run under