Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VDx1n-0003j8-Gx for pgsql-performance@arkaria.postgresql.org; Mon, 26 Aug 2013 13:40:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VDx1m-000148-Sz for pgsql-performance@arkaria.postgresql.org; Mon, 26 Aug 2013 13:40:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VDx1m-00013q-0E for pgsql-performance@postgresql.org; Mon, 26 Aug 2013 13:40:18 +0000 Received: from mail.gransy.com ([2001:1528:137::f1]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VDx1j-0002bb-8N for pgsql-performance@postgresql.org; Mon, 26 Aug 2013 13:40:17 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id E43C7508BE9; Mon, 26 Aug 2013 15:40:11 +0200 (CEST) X-Virus-Scanned: G-Hosting.cz + Station.cz + Klenot.cz + Subreg.cz amavisd-new at antispam.gransy.com Received: from mail.gransy.com ([82.208.44.189]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id XmLsC5nSj5_e; Mon, 26 Aug 2013 15:40:20 +0200 (CEST) Received: by mail.gransy.com (Postfix, from userid 5000) id 9FCFD508BED; Mon, 26 Aug 2013 15:40:11 +0200 (CEST) Received: from sq.gransy.com (elizabeth.gransy.com [89.187.132.199]) by mail.gransy.com (Postfix) with ESMTPA id 81D4C508BE9; Mon, 26 Aug 2013 15:40:10 +0200 (CEST) Received: from 212.47.19.46 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Mon, 26 Aug 2013 15:40:15 +0200 Message-ID: In-Reply-To: References: Date: Mon, 26 Aug 2013 15:40:15 +0200 Subject: Re: Poor performance on simple queries compared to sql server express From: "Tomas Vondra" To: "Adam Ma'ruf" Cc: "Pavel Stehule" , "pgsql-performance@postgresql.org" User-Agent: SquirrelMail/1.4.22 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Pg-Spam-Score: -1.9 (-) 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 On 26 Srpen 2013, 15:02, Adam Ma'ruf wrote: > Sure > > I just upgraded to 9.2.4. The query is: > SELECT quebec_four > , sierra > , SUM(dollaramount) as dollaramount > FROM alpha_quebec_echo > GROUP BY quebec_four > , sierra > > alpha_quebec_echo has 5,409,743 rows and 39 columns. Quebec_four and > sierra are both varchar, dollar amount is a floating point field. It has > no indexes (but neither did the mssql express table). Any other details > you need? > > Thanks, > A Hi, It's quite clear why the query is so slow - the plan is using on-disk sort with ~5M rows, and that's consuming a lot of time (almost 120 seconds). I'm wondering why it chose the sort in the first place. I'd guess it'll choose hash aggregate, which does not require sorted input. Can you try running "set enable_sort = false" and then explain of the query? If that does not change the plan to "HashAggregate" instead of "GroupAggregate", please check and post values of enable_* and cost_* variables. Another question is why it's doing the sort on disk and not in memory. The explain you've posted shows it requires ~430MB on disk, and in my experience it usually requires ~3x that much to do the in-memory sort. I see you've set work_mem=4GB, is that correct? Can you try with a lower value - say, 1 or 2GB? I'm not sure how this works on Windows, though. Maybe there's some other limit (and SQL Server is not hitting it, because it's native Windows application). Can you prepare a testcase (table structure + data) and post it somewhere? Or at least the structure, if it's not possible to share the data. Also, output from "select * from pg_settings" would be helpful. Tomas -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance