Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iohNl-0008Lv-Mo for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2020 05:26:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iohNk-0005b0-4q for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2020 05:26:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iohNj-0005ar-OS for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2020 05:26:19 +0000 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iohNb-0006Lu-Rh for pgsql-hackers@postgresql.org; Tue, 07 Jan 2020 05:26:18 +0000 Received: by mail-yw1-xc44.google.com with SMTP id v126so22931146ywc.10 for ; Mon, 06 Jan 2020 21:26:11 -0800 (PST) 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=PXXybxWqeWfzKbQWFqC8fi+qABjxtGrqr8TjVB04cD4=; b=utGOWHPxIAxRV87cCu5c2Bu9LVNfPmEON37YWovXHvWssCuTSsRrIn9B+Q1HGaMyzN KpJQcIqMf/nWVmQCUUO0C0xO92ClTT4jk828LnhAokN4zsG2xZGLGgbIB7055WdIlTSB p+IvxW525kuwxpFfyCncc+MgMDCpbf8HpQp11vapjO+FuZsuq/yY9WKuoHkzmQc1wAKW Y3wHamgW1xBI4zKl4RBt8RdGVJmdAaCOiVAGZNPIuh4zyXOzxeGHOn5MlnJA5OEEjIE0 FBXIzBAh20Syrv3KLIZ5M0dvgtyFWE5IKX0/DCz8+PzNfXKOaAkJZ8/OuiPHTTKBLR7+ 3ycQ== 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=PXXybxWqeWfzKbQWFqC8fi+qABjxtGrqr8TjVB04cD4=; b=ooKtUr/nI4kAcFrY6HlXK4TMM+TTpsAJi4Twb1OJCPzbaCW4BX2+QRKXXiGiN/50uE MP2MMsjrx8m9bnYN08QyvN61eeiddsgSJfarxTQKy+AI18XSPyAvgHRykrYoZ4m5Df+U NTfWgB0GjnDWQi7dAxwpmrC5JAP3b4YjYl6OvTcY/NN3YQyq49/p9KWKQVU0UpAJ1Dom Sa7/uazPdmbMAXlys7TuYYxiAG7w5vY/LBSxVPWTt2O1qpQyrjWipC61Kb+MLjdn5KxE YLGuan9LdXlxVjz469GoKe/bVbkscWs4atlDuSPFdSq3/ScPcaHyHFqqLMAgO4cGMgGL WASw== X-Gm-Message-State: APjAAAWU2i8DD2jXSXS23I/yFoUCDo+TkeeJt/yXvvzShRLCgSmO9FXW q6e6MLO0+QIAo3b+CVyL/YU5xA== X-Google-Smtp-Source: APXvYqx7G0QgaRXWW+MQiY+0tZzr5NwAT5UlzxBkLulxgOPstQvEMBCCsHvcdoSKNalmr9NbnYOpRQ== X-Received: by 2002:a0d:c5c2:: with SMTP id h185mr77044822ywd.287.1578374769411; Mon, 06 Jan 2020 21:26:09 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d207sm29106946ywa.62.2020.01.06.21.26.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2020 21:26:08 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id AC8F88009F4; Mon, 6 Jan 2020 23:26:06 -0600 (CST) Date: Mon, 6 Jan 2020 23:26:06 -0600 From: Justin Pryzby To: Dilip Kumar Cc: Michael Paquier , Jeff Janes , Claudio Freire , pgsql-hackers Subject: Re: bitmaps and correlation Message-ID: <20200107052606.GP12066@telsasoft.com> References: <20190101225615.GF25379@telsasoft.com> <20190101230230.GA20769@telsasoft.com> <20191102202617.GO4999@telsasoft.com> <20191201033437.GG2355@paquier.xyz> <20191201160019.GI16647@telsasoft.com> <20200106195853.GL12066@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jan 07, 2020 at 09:21:03AM +0530, Dilip Kumar wrote: > On Tue, Jan 7, 2020 at 1:29 AM Justin Pryzby wrote: > > > > Find attached cleaned up patch. > > For now, I updated the regress/expected/, but I think the test maybe has to be > > updated to do what it was written to do. > > I have noticed that in "cost_index" we have used the indexCorrelation > for computing the run_cost, not the number of pages whereas in your > patch you have used it for computing the number of pages. Any reason > for the same? As Jeff has pointed out, high correlation has two effects in cost_index(): 1) the number of pages read will be less; 2) the pages will be read more sequentially; cost_index reuses the pages_fetched variable, so (1) isn't particularly clear, but does essentially: /* max_IO_cost is for the perfectly uncorrelated case (csquared=0) */ pages_fetched(MIN) = index_pages_fetched(tuples_fetched, baserel->pages, (double) index->pages, root); max_IO_cost = pages_fetchedMIN * spc_random_page_cost; /* min_IO_cost is for the perfectly correlated case (csquared=1) */ pages_fetched(MAX) = ceil(indexSelectivity * (double) baserel->pages); min_IO_cost = (pages_fetchedMAX - 1) * spc_seq_page_cost; My patch 1) changes compute_bitmap_pages() to interpolate pages_fetched using the correlation; pages_fetchedMIN is new: > Patch > - pages_fetched = (2.0 * T * tuples_fetched) / (2.0 * T + tuples_fetched); > + pages_fetchedMAX = (2.0 * T * tuples_fetched) / (2.0 * T + tuples_fetched); > + > + /* pages_fetchedMIN is for the perfectly correlated case (csquared=1) */ > + pages_fetchedMIN = ceil(indexSelectivity * (double) baserel->pages); > + > + pages_fetched = pages_fetchedMAX + indexCorrelation*indexCorrelation*(pages_fetchedMIN - pages_fetchedMAX); And, 2) also computes cost_per_page by interpolation between seq_page and random_page cost: + cost_per_page_corr = spc_random_page_cost - + (spc_random_page_cost - spc_seq_page_cost) + * (1-correlation*correlation); Thanks for looking. I'll update the name of pages_fetchedMIN/MAX in my patch for consistency with cost_index. Justin