Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lekBP-0002kS-Te for pgsql-performance@arkaria.postgresql.org; Thu, 06 May 2021 20:01:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lekBO-0002fS-SG for pgsql-performance@arkaria.postgresql.org; Thu, 06 May 2021 20:01:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lekBO-0002fK-Ev for pgsql-performance@lists.postgresql.org; Thu, 06 May 2021 20:01:14 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lekBH-0004wB-K8 for pgsql-performance@lists.postgresql.org; Thu, 06 May 2021 20:01:14 +0000 Received: by mail-oi1-x233.google.com with SMTP id l6so6653190oii.1 for ; Thu, 06 May 2021 13:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ihvSUm5/HpaNG5FN6DVwUQfRCH2MG+g3CcvW4Fdao/0=; b=ro5C07hIMT+70WkJ1GIlwYqe/pOFhR/rZGz65EorK/rkoPE6D0eltWNwxZmdvbA6sS PAo/rCo4J8Ds51JvDkmjMO8CniRcPnhrmaq3+U+YFN3GuxC96MmHPmZEEF2RyAXYR7OE BBwSWBQ4Du3gfZwS/pNCzwr4R2+84ZQiuAsXfFMj3oArFvaJHbcV69P0gaqotQFexcI6 6yTaa6mRDaFya44z1tGyEmJt/m/XoR5rufO1CLewVMKu4Qi3lEWKPpPpfO+uCrP6W/9n wBKFrz10QcGqxD1LRrgYNINsXi7VI3oZAKo995D2xObcQQNLS40IsAomIGeGZ7gZoeXl W6rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ihvSUm5/HpaNG5FN6DVwUQfRCH2MG+g3CcvW4Fdao/0=; b=OLZcIr51tPrH5UxHPvAszddtn9ZEyx7t5kkvgfk+zrfrrIMyiL0hbOh6vgxv65nZjH m7xYR8Gaht5zBcuB0lJb4WOpFTUFtTjgjQz2GsEgdOM7paI0MSB8B7an46husEAA+8p1 c7+3Z+w5yMvhFE05mS44nzuhLSD0eRJpD0bvFvlojJcfyaqhbNqrQPqnAyXAg/EiP6xQ Qj92whvw0thD04lgl+GkEbIzR/HsmUaw8Jpa55254OM0PoBPzk+25em/Lax1dnqR3qql 5NWT5gSZ8aO9OTpKAZ+WINI3tuDw1/oZZC3NYCFanKiQsyhQgCgdtUIux8HllsfpE7gm refA== X-Gm-Message-State: AOAM531AECfdXivY7OYggBDV8q5RunWx+35rpIM3+I5lXfTsQrWTErce /UK8Y7KjTJK8zRy8aV5gfXKDv2zhZXoLJQ== X-Google-Smtp-Source: ABdhPJxx3icEqsqm+atni5a11CulIEx3I0vi2xpltoBhY8pzcnSZk1alaxiEmOOx4mfrmUnoSH1paw== X-Received: by 2002:a54:4581:: with SMTP id z1mr12031479oib.43.1620331265684; Thu, 06 May 2021 13:01:05 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id w3sm744744otg.78.2021.05.06.13.01.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 May 2021 13:01:04 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 80587800897; Thu, 6 May 2021 15:01:03 -0500 (CDT) Date: Thu, 6 May 2021 15:01:03 -0500 From: Justin Pryzby To: Semen Yefimenko Cc: pgsql-performance@lists.postgresql.org Subject: Re: Very slow Query compared to Oracle / SQL - Server Message-ID: <20210506200103.GP27406@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, May 06, 2021 at 04:38:39PM +0200, Semen Yefimenko wrote: > Hi there, > > I've recently been involved in migrating our old system to SQL Server and > then PostgreSQL. Everything has been working fine so far but now after > executing our tests on Postgres, we saw a very slow running query on a > large table in our database. > I have tried asking on other platforms but no one has been able to give me > a satisfying answer. > With the help of some people in the slack and so thread, I've found a > configuration parameter which helps performance : > set random_page_cost = 1; I wonder what the old query plan was... Would you include links to your prior correspondance ? > -> Parallel Bitmap Heap Scan on schema.logtable (cost=5652.74..327147.77 rows=214503 width=2558) (actual time=1304.813..20637.462 rows=171947 loops=3) > Recheck Cond: ((logtable.entrytype = 4000) OR (logtable.entrytype = 4001) OR (logtable.entrytype = 4002)) > Filter: (logtable.archivestatus <= 1) > Heap Blocks: exact=103962 > Buffers: shared hit=141473 read=153489 > > ------------------------------------------------------------------------------------------------------------------------- > | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | > ------------------------------------------------------------------------------------------------------------------------- > | 0 | SELECT STATEMENT | | 6878 | 2491K| | 2143 (1)| 00:00:01 | > | 1 | SORT ORDER BY | | 6878 | 2491K| 3448K| 2143 (1)| 00:00:01 | > | 2 | INLIST ITERATOR | | | | | | | > |* 3 | TABLE ACCESS BY INDEX ROWID BATCHED| logtable | 6878 | 2491K| | 1597 (1)| 00:00:01 | > |* 4 | INDEX RANGE SCAN | idx_entrytype | 6878 | | | 23 (0)| 00:00:01 | > ------------------------------------------------------------------------------------------------------------------------- > > Is there much I can analyze, any information you might need to further > analyze this? Oracle is apparently doing a single scan on "entrytype". As a test, you could try forcing that, like: begin; SET enable_bitmapscan=off ; explain (analyze) [...]; rollback; or begin; DROP INDEX idx_arcstatus; explain (analyze) [...]; rollback; You could try to reduce the cost of that scan, by clustering on idx_arcstatus, and then analyzing. That will affect all other queries, too. Also, the "clustering" won't be preserved with future inserts/updates/deletes, so you may have to do that as a periodic maintenance command. -- Justin