Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rISib-008l8O-E7 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 12:09:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rISiZ-00560c-FJ for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 12:08:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rISiZ-00560U-4m for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2023 12:08:59 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rISiR-00E8kK-IY for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2023 12:08:57 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2ccae5719cfso33124161fa.1 for ; Wed, 27 Dec 2023 04:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1703678930; x=1704283730; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cLtg4jkz4s/BvSXqTTDqyV7At8yc9II1z4sxjy77nBc=; b=hTmuxN8xSA0kDhI5YRKSTS8DeTpAToCRT6BhwR5Ll/KUSOIlz/yahnmt1XJ9cPy47Y 2/u3RBOrV3sI5ZnfJePu2McEh4WrQt5LqLpRhxOzoiAoqWltgz91TmXsicxtkzTFhyjm giE36xScpRoYqyQlBQyrfd/n1W58tN64GLK3uZLqNdsBvnAe1vEkJaHeI7KvK9MT9572 Ysxtr3VMNSMiycMIJQh57ospuQJIXtyZFmpBeIY03LuoTpFOJKmOL54jW7Douq6e8b9V xmJBkZo6S09RbqPbDXWkAXCGiGsTs479bWsb1Y/PNLiazwB+SbUKbTCIduabioUEolhf 2Jhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703678930; x=1704283730; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cLtg4jkz4s/BvSXqTTDqyV7At8yc9II1z4sxjy77nBc=; b=qcWx+k1LyXe8VWeLMocyU7+BidfGjQgSvJ2sm0WXVoCQjHG7fFW5LX1J5HFiqKnJbB 6PNYBUM645/+Zg1wUbJxhXeTF/Aji/HWzR21a6v+N1zjvIA0TZBNJks/YyBU3WQPAbKr fvymbJz2hkDASaKc3x1faqbILMuBrvohjIJC8/paQR+QipgYWglshAmzXxMEZJ34vpJ7 3175sHN+H5KtLdjucH7O8TK9fxG6XjN/6TnyddoSwhSNlfOStWNpMFt8/hIW05t/b2x1 2oSKq3vCp+fL26ESrgU8tkdK2oTxxvxDLvQH7ZJVTjtJaJUvT/WPcUSyusnmgFCOAUVR SsHw== X-Gm-Message-State: AOJu0YzWTB2FHlYqR4uE6FTyck10T9g6IBfabJ2XgMFekYANkcQOj4+V p+vkqxRuRwbmgvVsnNy6OcTdjV/e8pX1 X-Google-Smtp-Source: AGHT+IHkVckGRGbPJRSkOeijcSSkamt0tr0N80s2iODZ9kiz3+NTc/lTIxvL9rYndKa9uNbN/BIVXw== X-Received: by 2002:a2e:8e8d:0:b0:2cc:ce6d:5adb with SMTP id z13-20020a2e8e8d000000b002ccce6d5adbmr685341ljk.34.1703678929877; Wed, 27 Dec 2023 04:08:49 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id y12-20020a05651c154c00b002cc522d6da7sm2539287ljp.24.2023.12.27.04.08.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Dec 2023 04:08:49 -0800 (PST) Message-ID: <4e49c72e-f8a5-de1a-4ef4-36529bee1d65@enterprisedb.com> Date: Wed, 27 Dec 2023 13:08:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Statistics Import and Export Content-Language: en-US To: Tom Lane , Bruce Momjian Cc: Corey Huinker , Ashutosh Bapat , pgsql-hackers@lists.postgresql.org References: <76596388-6fe6-0baf-351d-734458a46d76@enterprisedb.com> <4268d862-7784-f76f-d7f1-359b0b4db67c@enterprisedb.com> <2090613.1703618344@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <2090613.1703618344@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/26/23 20:19, Tom Lane wrote: > Bruce Momjian writes: >> I think we need a robust API to handle two cases: > >> * changes in how we store statistics >> * changes in how how data type values are represented in the statistics > >> We have had such changes in the past, and I think these two issues are >> what have prevented import/export of statistics up to this point. >> Developing an API that doesn't cleanly handle these will cause long-term >> pain. > > Agreed. > I agree the format is important - we don't want to end up with a format that's cumbersome or inconvenient to use. But I don't think the proposed format is somewhat bad in those respects - it mostly reflects how we store statistics and if I was designing a format for humans, it might look a bit differently. But that's not the goal here, IMHO. I don't quite understand the two cases above. Why should this affect how we store statistics? Surely, making the statistics easy to use for the optimizer is much more important than occasional export/import. >> In summary, I think we need an SQL-level command for this. > > I think a SQL command is an actively bad idea. It'll just add development > and maintenance overhead that we don't need. When I worked on this topic > years ago at Salesforce, I had things set up with simple functions, which > pg_dump would invoke by writing more or less > > SELECT pg_catalog.load_statistics(....); > > This has a number of advantages, not least of which is that an extension > could plausibly add compatible functions to older versions. The trick, > as you say, is to figure out what the argument lists ought to be. > Unfortunately I recall few details of what I wrote for Salesforce, > but I think I had it broken down in a way where there was a separate > function call occurring for each pg_statistic "slot", thus roughly > > load_statistics(table regclass, attname text, stakind int, stavalue ...); > > I might have had a separate load_statistics_xxx function for each > stakind, which would ease the issue of deciding what the datatype > of "stavalue" is. As mentioned already, we'd also need some sort of > version identifier, and we'd expect the load_statistics() functions > to be able to transform the data if the old version used a different > representation. I agree with the idea that an explicit representation > of the source table attribute's type would be wise, too. > Yeah, this is pretty much what I meant by "functional" interface. But if I said maybe the format implemented by the patch is maybe too close to how we store the statistics, then this has exactly the same issue. And it has other issues too, I think - it breaks down the stats into multiple function calls, so ensuring the sanity/correctness of whole sets of statistics gets much harder, I think. I'm not sure about the extension idea. Yes, we could have an extension providing such functions, but do we have any precedent of making pg_upgrade dependent on an external extension? I'd much rather have something built-in that just works, especially if we intend to make it the default behavior (which I think should be our aim here). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company