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 1jvjUt-0001AJ-3u for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 15:39:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jvjUr-0001iq-RK for pgsql-general@arkaria.postgresql.org; Wed, 15 Jul 2020 15:39:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jvjUr-0001f3-Jo for pgsql-general@lists.postgresql.org; Wed, 15 Jul 2020 15:39:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jvjUp-0003zy-Fm for pgsql-general@lists.postgresql.org; Wed, 15 Jul 2020 15:39:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 06FFcv2M3077130; Wed, 15 Jul 2020 11:38:57 -0400 From: Tom Lane To: Adam Sanchez cc: pgsql-general@lists.postgresql.org Subject: Re: 2 million queries against a table In-reply-to: References: Comments: In-reply-to Adam Sanchez message dated "Wed, 15 Jul 2020 17:10:30 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3077128.1594827537.1@sss.pgh.pa.us> Date: Wed, 15 Jul 2020 11:38:57 -0400 Message-ID: <3077129.1594827537@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adam Sanchez writes: > I need to run 2 million queries against a three columns table t > (s,p,o) which size is 10 billions rows. The data type of each column > is string. The server has 512G RAM, 32 cores and 14T SSD (RAID 0) > Only two types of queries: > select s p o from t where s = param > select s p o from t where o = param TBH, this is a pretty silly way to use a SQL database. Put the probe values into a temporary table (in batches, perhaps) and do a join. The per-row cost of that sort of approach will be multiple orders of magnitude smaller than a query per row. regards, tom lane