Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBMee-0004JZ-73 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Apr 2018 15:48:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fBMed-0002pE-3V for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Apr 2018 15:48:23 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBMec-0002p3-Od for pgsql-hackers@lists.postgresql.org; Wed, 25 Apr 2018 15:48:22 +0000 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fBMeX-0008NC-J1 for pgsql-hackers@postgresql.org; Wed, 25 Apr 2018 15:48:22 +0000 Received: by mail-qt0-x241.google.com with SMTP id s2-v6so27412124qti.2 for ; Wed, 25 Apr 2018 08:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=NGedqXxlN2Czdg01HEoi+rEUuPYIBCWbVtMKmtaMl+0=; b=nOhsgV4fjiJn8J4sqWCLFHYJz/tjQ1FyoCVUhUYTZDFu4WVKKzBci73KRCMnyFazuW oUSbZnDoh2MaQQIp6tKx89IiD1wERDcUByE5k3cNAAUCoEIlEZjPj5TkQemvNlNqoHg9 RJdxd06q270Kyi41McPDRJ1FTbC4Tqd7f8ufIFPBLGMtLKMC0B7oenLsCmU5oUYnjm5r V+bow8UxfIp3pRurLVMKZA7p8pdn54hXW+4QDhn357nhilN9xYFPenlGIYKY4Pby3tJq RHL6ihRaDN5dnrs22+1oUP9rBzCvzfRUY2zUrrXgOquVSEXiSOD78ouK6bRNmVZbfmMR cP7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=NGedqXxlN2Czdg01HEoi+rEUuPYIBCWbVtMKmtaMl+0=; b=CkxeIO2Yuz5KphdchBistOK2ghzTyQxVegHM8mASDxXPlauJJJEYsP+30ZjUXovaq9 pCKfaxbxNQSIrvqw1PCWzMHwPKG8x4tdJNNnwsfPW3GY4W+HgHrt9x86WEBrhHgagqXn lCOmOwQSg9qmuLbB/RfJNJHHS+1w30PU7vI33I/U2d1PM3Y3QkBCRd1+3ZHpZ8+2/Xzu cONrSvvUKnnJF+7O3wvlKLbtwDwWRuhpgqayFOhk5ITxjVOAbcL8dAdT6Ce16meqG41f F1LeSqmHdmwC+xZbW78BHETHVaclP8YQzW7loNWSmYnAZVgJKsKkJDdE9d7JkKgmyFuj RtGA== X-Gm-Message-State: ALQs6tDkPPlWh/wX6XeWhPnlHvDJf7Dqi8jSSvqSmr5p2K7dsnLIvceH jcJpylJ3WbSUgYcm5L7FzmeVtod+Lk2d7KImGANjFXqVSH3NPqxTCN02gLbf0AZiNXzP9+VymF0 XM1K6z90bL4TBr2QVaDXJC+57HiNTvK16JvZ71IxMj99+5In36guX90jZfRJPailzbADmNekRUs wxWsGbF3oTvYch X-Google-Smtp-Source: AB8JxZqHBrsX819vAo6ZFyL7W4KDgVbfmpYeV+fSfCrLYwPAQumNbZyVfV4Kbp3cAn7avTjonSeknw== X-Received: by 2002:aed:38e2:: with SMTP id k89-v6mr33539089qte.264.1524671295331; Wed, 25 Apr 2018 08:48:15 -0700 (PDT) Received: from [192.168.10.146] ([98.122.175.38]) by smtp.gmail.com with ESMTPSA id e23-v6sm13958293qtp.6.2018.04.25.08.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 08:48:14 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: unused_oids script is broken with bsd sed To: John Naylor , Stas Kelvich Cc: Tom Lane , PostgreSQL Hackers References: <37D774E4-FE1F-437E-B3D2-593F314B7505@postgrespro.ru> <34a54c54-9132-1254-2bc3-d3489fb79728@2ndQuadrant.com> <4473.1524665917@sss.pgh.pa.us> <4DE444D1-DDE9-460F-AC2F-EB1B73D94A2D@postgrespro.ru> Message-ID: <25f3ae08-5347-bd63-7866-05c135fdcfa3@2ndQuadrant.com> Date: Wed, 25 Apr 2018 11:48:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------639912E45C740DCCD9F2CFF4" Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------639912E45C740DCCD9F2CFF4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 04/25/2018 10:55 AM, John Naylor wrote: > On 4/25/18, Stas Kelvich wrote: >>> On 25 Apr 2018, at 17:18, Tom Lane wrote: >>> I think we should rewrite >>> both of them to use the Catalog.pm infrastructure. >> Okay, seems reasonable. I'll put shared code in Catalog.pm and >> update patch. > I don't think you need any new code in Catalog.pm, I believe the > suggestion was just to use that module as a stable interface to the > data. Looking at your patch, I'll mention that we have an idiom for > extracting #define'd OID symbols, e.g.: > > my $FirstBootstrapObjectId = Catalog::FindDefinedSymbol( > 'access/transam.h', \@include_path, 'FirstBootstrapObjectId'); > > This is preferred over using awk, which would have its own portability > issues (Windows for starters). > > While I'm thinking out loud, it might be worthwhile to patch genbki.pl > for the duplicate test, since they're run at the same time anyway (see > catalog/Makefile), and we've already read all the data. > The logic for getting the set of oids should be centralized, if not in Catalog.pm then in a script which serves both for dup0licate_oids and unused_oids. Here is something I cobbled together for the latter approach. It could probably improve by using Catalog::FindDefinedSymbol() cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------639912E45C740DCCD9F2CFF4 Content-Type: application/x-perl; name="unused_oids.pl" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="unused_oids.pl" #!/usr/bin/perl use strict; use warnings; my %oidcounts; BEGIN { @ARGV = (glob("pg_*.h"), glob("pg_*.dat"), qw(indexing.h toasting.h)); } while (<>) { next if /^CATALOG\(.*BKI_BOOTSTRAP/; next unless /\boid *=> *'(\d+)'/ || /^CATALOG\([^,]*, *(\d+).*BKI_ROWTYPE_OID\((\d+),/ || /^CATALOG\([^,]*, *(\d+)/ || /^DECLARE_INDEX\([^,]*, *(\d+)/ || /^DECLARE_UNIQUE_INDEX\([^,]*, *(\d+)/ || /^DECLARE_TOAST\([^,]*, *(\d+), *(\d+)/; $oidcounts{$1}++; $oidcounts{$2}++ if $2; } if ($0 eq 'duplicate_oids') { my $found = 0; foreach my $oid (sort { $a <=> $b } keys %oidcounts) { next unless $oidcounts{$oid} > 1; $found = 1; print "$oid\n"; } exit $found; } elsif ($0 eq 'unused_oids') { my $firstobj; open (my $handle,"../access/transam.h") || die "opening transam.h"; while (<$handle>) { next unless /^#define\s+FirstBootstrapObjectId\s+(\d+)/; $firstobj = $1; last; } close($handle); my @sortedoids = sort { $a <=> $b } keys %oidcounts; my $last = 0; foreach my $oid (@sortedoids ) { if ($oid > $last + 1) { if ($oid > $last + 2) { print $last + 1, " - ", $oid - 1, "\n"; } else { print $last + 1,"\n"; } } $last = $oid; } print $last + 1," - ", $firstobj - 1,"\n"; exit 0; } --------------639912E45C740DCCD9F2CFF4--