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 1iGOgb-0002GX-1s for pgsql-general@arkaria.postgresql.org; Fri, 04 Oct 2019 14:36:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iGOgY-0006kj-CV for pgsql-general@arkaria.postgresql.org; Fri, 04 Oct 2019 14:35:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iGOgX-0006kF-Px for pgsql-general@lists.postgresql.org; Fri, 04 Oct 2019 14:35:58 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iGOgU-00031V-Sx for pgsql-general@postgresql.org; Fri, 04 Oct 2019 14:35:56 +0000 Received: by mail-qt1-x842.google.com with SMTP id c21so8774085qtj.12 for ; Fri, 04 Oct 2019 07:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interfacefinancial-com.20150623.gappssmtp.com; s=20150623; h=from:date:to:subject:message-id:reply-to:mime-version :content-disposition:user-agent; bh=Ftgn4A7bYbuSvc/ahq3EZWLC39iSlrLJGqljfU79690=; b=DRQWzEjC8jS08WGFaCtLs3a7LQhBqJwG5njx/yskTAxrVyVK0Nqb52FbLN+NC8orBM YHVOz7Gnp2eN/mQqwIm5Il9ys8zeCESQTXtmRBCFKksIrFUR/sbLkd9mIa34UCAhs2LD pbEIPNrR+p1oqhqEB6JxFO1h97wUYGgctKKi6M3SAkuzMylT8e+DicmyFD0/yzyB4a2k IO/ZRCbZm173R+BheJ8sGPFZBtXnHi0n6jXHdjX4SmhPZWzhq7JzPNIgj8hreCRI/mXh CE6dpgtdktvKn9zYEEWvbbsDQg9l3Y7N6mYcYBGS612DOwD7lGkemdGr0y2Q+EAFeo0N nU2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:message-id:reply-to :mime-version:content-disposition:user-agent; bh=Ftgn4A7bYbuSvc/ahq3EZWLC39iSlrLJGqljfU79690=; b=Ftzbh7lZirxsYiIMOu9fEaNSrcfoN4+MLE8WSoEHdG3rrk+Z6gCNJCoVdYWNTiqvvu 8cVluW+XbB5G3F+7yUOCqwivb0yUvAaqiJP2dTuTGtrqhCK5wgdJ6YYyvsKR/32NT7Ca COUm6Nc/f1jJqlRzA0xkuGz47wDUWUVU5Ck/YTq6ecsDdAh4PM4Vlbi1w65oMV5mZNaQ t0LYlSal8lum6W6HyhScdoTLoQNsuWQk+BMhZaMn9RhtPDCkxTnCAYo4hMFyCiQ+xnSU Eupj31vcPfu2Vi/pJuui7YVVaQc0umhFgGd/ht9RYwXeqRsyLRdVWzIc+vwqFxA+pU/X bE3w== X-Gm-Message-State: APjAAAWW5SVoJufn9/+EK6bVgEWoYkxdNCOwwAOZlUzN9Blv4HpdSKg5 D2/Dwt2SaHpI8LnEIU98s+iGrNG26tQ= X-Google-Smtp-Source: APXvYqw1hazuK2IyzXTcDBe9ayUREC+SyEeOLqxnlPZiD1XvJJsnBCNqELAbPH9s7qRkyQzOa26vGA== X-Received: by 2002:ac8:1af3:: with SMTP id h48mr15760461qtk.270.1570199753423; Fri, 04 Oct 2019 07:35:53 -0700 (PDT) Received: from debian (pool-173-66-25-111.washdc.fios.verizon.net. [173.66.25.111]) by smtp.gmail.com with ESMTPSA id q200sm2947743qke.114.2019.10.04.07.35.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 07:35:52 -0700 (PDT) From: Dmitry Bogatov X-Google-Original-From: Dmitry Bogatov Date: Fri, 4 Oct 2019 15:35:51 +0100 To: pgsql-general@postgresql.org Subject: Unexpected plan width with foreign data wrapper Message-ID: <20191004143550.GA30189@debian> Reply-To: dbogatov+patch@interfacefinancial.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello. I work on fixing test suite (make installcheck) failures in Multicorn project[1]. The purpose of project is to make it possible to write Foreign Data Wrappers[2] in Python, not in C[3]. Test suite executes SQL statements with psql and compares output with expected. If they are different, test is considered failed. Major source of test failures is width estimation in query plan explaination. For example, for following statements: CREATE EXTENSION multicorn; CREATE server multicorn_srv foreign data wrapper multicorn options ( wrapper 'multicorn.testfdw.TestForeignDataWrapper' ); CREATE user mapping for postgres server multicorn_srv options (usermapping 'test'); CREATE foreign table testmulticorn ( test1 date, test2 timestamp ) server multicorn_srv options ( option1 'option1', test_type 'date' ); -- Test sort pushdown asked EXPLAIN SELECT * FROM testmulticorn ORDER BY test1 DESC; I have mismatch, described by this `diff expected actual`: - Foreign Scan on testmulticorn (cost=10.00..400.00 rows=20 width=20) + Foreign Scan on testmulticorn (cost=10.00..400.00 rows=20 width=12) Width 20 is understandable: this is value assigned to `baserel->reltarget->width` in GetForeignRelSize callback function. Origin of value `12' is unknown to me. I have some observations on how width estimate propagates through callback functions, though. Behaviour differs on different versions of postgresql: 1. Postgresql-11 * Value assigned to `baserel->reltarget->width` in GetForeignRelSize callback stays same in GetForeignPaths, but in GetForeignPlan it is changed. In this test, from 20 to 12. * If I assign it in GetForeignPlan function back to value 20 (value can be transfered via `baserel->fdw_private` field), expected value 20 will appear in output of `psql`. Test fixed, but with no understanding why. 2. Postgresql-9.6 * Value assigned to `baserel->reltarget->width` in GetForeignRelSize stays the same in GetForeignPaths and GetForeignPlan, but `psql` still outputs another value. Test failed.