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 1p7xtO-00013a-V4 for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Dec 2022 12:08:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7xtN-0008Vl-Qe for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Dec 2022 12:08:13 +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 1p7xtN-0008Vb-6G for pgsql-hackers@lists.postgresql.org; Wed, 21 Dec 2022 12:08:13 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p7xtK-0007p8-Fr for pgsql-hackers@lists.postgresql.org; Wed, 21 Dec 2022 12:08:12 +0000 Received: by mail-wr1-x432.google.com with SMTP id o5so14712909wrm.1 for ; Wed, 21 Dec 2022 04:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UUqS08fO1gZVR631qri0pkffZV5G2cSBJOGBbB0OShg=; b=TzluZ3O+GorsSmswXK/1phlDGG3g3TLlQWGGGkAXYBquKIcUwHUoKHkwJB6jS6KHem Pv47aWUlvsjb0B4cIRTuytXXsp2nI3u7agl0fN1fJ7bG2nR34NOH3lpelLypzfltjqrr M49EjtljkemmDircmxNS6u2OotKdhmkfKLDUUfSfq650mRfO8SkEnBejezHaRQ3rX3eX qIgH6igDaESlq/VFkckVoXkaZCXCW4VYViuwShTNfrBY7xdIWhP1zCK2USdMqYOxQDIs Pz1vbPQbNtkWAcH3kyEXcwshzOZ7Y0U55fncfPmye0RavYB17+Rfl+derFLx7d++QGFL CroQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UUqS08fO1gZVR631qri0pkffZV5G2cSBJOGBbB0OShg=; b=vUp2hpsAwgxh7xjawRoYL+7e50HvXbrU7vY8x7oZu/ToZIq2XQuy+bN4WQ1i3lIvSX NwmrxzqVVvr3acuRCz8+F5jRDX6b3kYF4SqpRthGugYBWcAJ6XujC4iYVtIxf3ZjRrFC R67O426HPqqGQ5d0FCuVMcwDPmNNS6roh1gisoyNlSUaVm3f9KQSVnnPEVU+pDyJUly3 GcyTaK1zuEvZPOyldU8WtJOeQ/qWp7Y3nzoDsdXqcGcMQMwiXqUejH8/NGyqIBnB8keH S2+cbf2ook+LZo1PfHM8s8dPssS7kKldC+boU/2+JrjzbQEkTgqDEiwJbx2DZ1cYw2pV D1dA== X-Gm-Message-State: AFqh2kromO3wrDdb/ScNNyhzENRtmSaMNcN/UWKN3rK44+W7+H/LQzyJ 9/aIzNPsm3ZawkMPOHtUHOxCOHpnNe/PXgxD1GAeZF3MlVgxIRVeil2+fLEa0cKhjVl1ZQC/ZDK 3t5m4eVJmmFgTosoILPU6O4MdiItg8W7zq5jJBicOWlew1+VEFNjxEEZsx9ijdefVICSURw2C2g RiBe/R2io1X63f9SKVOoNgrZ0f9/fVrBeLTVV+BXZgw5yB3skI+j4amnbnx0IuEFneE5PnXD2jX XNXtZ+ySjWRl/5Dd4Y9oflVFM8ZiCTS/UuZdqdk3jhQ2VByiVjG7eueOGr3 X-Google-Smtp-Source: AMrXdXvQsoeCFyDpD74IE0EM1yxc94FC8IaRkj1oZWYneI24T8AJUfi+joyILPNJy/6rSKzJlDRsdw== X-Received: by 2002:a5d:5408:0:b0:242:51ae:e9ca with SMTP id g8-20020a5d5408000000b0024251aee9camr925432wrv.35.1671624489298; Wed, 21 Dec 2022 04:08:09 -0800 (PST) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id q9-20020a05600000c900b0024228b0b932sm17929181wrx.27.2022.12.21.04.08.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Dec 2022 04:08:08 -0800 (PST) Message-ID: Date: Wed, 21 Dec 2022 13:08:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: postgres_fdw: using TABLESAMPLE to collect remote sample To: Tom Lane , James Finnerty Cc: pgsql-hackers@lists.postgresql.org, Tomas Vondra References: <151e835f-55d6-ddbc-b5b4-07ee606aba44@enterprisedb.com> <03182011-10a4-97b4-7c70-d99aa1c11eed@enterprisedb.com> <167112207543.1120.12195641719862911275.pgcf@coridan.postgresql.org> <3377008.1671122816@sss.pgh.pa.us> Content-Language: en-US From: Tomas Vondra In-Reply-To: <3377008.1671122816@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/15/22 17:46, Tom Lane wrote: > James Finnerty writes: >> This patch looks good to me. I have two very minor nits: The inflation >> of the sample size by 10% is arbitrary but it doesn't seem unreasonable >> or concerning. It just makes me curious if there are any known cases >> that motivated adding this logic. > > I wondered why, too. > Not sure about known cases, but the motivation is explained in the comment before the 10% is applied. The repluples value is never going to be spot on, and we use that to determine what fraction of the table to sample (because all built-in TABLESAMPLE methods only accept fraction to sample, not expected number of rows). If pg_class.reltuples is lower (than the actual row count), we'll end up with sample fraction too high. That's mostly harmless, as we'll then discard some of the rows locally. But if the pg_class.reltuples is higher, we'll end up sampling too few rows (less than targrows). This can happen e.g. after a bulk delete. Yes, the 10% value is mostly arbitrary, and maybe it's pointless. How much may the stats change with 10% larger sample? Probably not much, so is it really solving anything? Also, maybe it's fixing the issue at the wrong level - if stale reltuples are an issue, maybe the right fix is making it more accurate on the source instance. Decrease autovacuum_vacuum_scale_factor, or maybe also look at pg_stat_all_tables or something. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company