Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YCga0-0005uP-Gc for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Jan 2015 03:31:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YCgZz-0005Qr-FC for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Jan 2015 03:31:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YCgZy-0005QW-Gc for pgsql-bugs@postgresql.org; Sun, 18 Jan 2015 03:31:10 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YCgZr-0004wZ-77 for pgsql-bugs@postgresql.org; Sun, 18 Jan 2015 03:31:09 +0000 MIME-Version: 1.0 Subject: BUG #12584: small bug about estimation of rows To: pgsql-bugs@postgresql.org From: t.katsumata1122@gmail.com Date: Sun, 18 Jan 2015 03:30:20 +0000 Message-ID: <20150118033020.1991.7172@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.1 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 12584 Logged by: Tomonari Katsumata Email address: t.katsumata1122@gmail.com PostgreSQL version: Unsupported/Unknown Operating system: CentOS 6.4 x86_64 Description: Hello, I found a bug about estimating rows without pg_class.reltuples. An empty table has NULL on its pg_class.reltuples. If PostgreSQL couldn't find pg_class.reltuples, the estimated rows are calculated by pagesize, size of the data and so on. Below is simple example. ======== testdb=# CREATE TABLE tbl (i bigint); CREATE TABLE testdb=# EXPLAIN SELECT * FROM tbl; QUERY PLAN ------------------------------------------------------- Seq Scan on tbl (cost=0.00..31.40 rows=2140 width=8) (1 row) ======== "rows=2140" is calculated at estimate_rel_size function of plancat.c like this. ======== plancat.c from master source. 508 int32 tuple_width; 509 510 tuple_width = get_rel_data_width(rel, attr_widths); 511 tuple_width += sizeof(HeapTupleHeaderData); 512 tuple_width += sizeof(ItemPointerData); 513 /* note: integer division is intentional here */ 514 density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width; ======== It should be using sizeof(ItemIdData) at line 512, so the estimated rows should be "rows=2260". I could understand ignoring alignment of data here from comment of the source code, but I couldn't find the reason of using sizeof(ItemPointerData) at this point. Usually this would not cause big problem, but it seems odd to me. Is there any reason to use sizeof(ItemPointerData) ? regards, -------------------- Tomonari Katsumata -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs