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 1pXp4G-0002ee-MC for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 19:58:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXp4E-0006ZT-Qb for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 19:58:18 +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 1pXp4E-0006ZD-Ey for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 19:58:18 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pXp4C-0001xv-DH for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 19:58:18 +0000 Received: by mail-oi1-x235.google.com with SMTP id r40so157673oiw.0 for ; Thu, 02 Mar 2023 11:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZIZ8MVxdY/J49c7D99WtfVmFs8xsaWTWkpgUihv6ww0=; b=DHJnvvp3sUKXGUQM1T7dR9EPGfbPc+z/s7f3XkVOyBWtzmaT7Gg+fTLANmWsMLDAaB KnqUizAywUSzBTVW68lz8K6dBpNZNafZ+tz6Zbv309d3E4hDoFG0jWwVLqKammGO7yvs 2q7hiI6xybZRX5Jc0+TnNg32Cg4gHY9J1A1oCA9OxEMmjJ7uyjvN1siUe9vLDLJobGIZ vKmitK9/PTkwwbMaGvBZyP+o7rQx70zUsn3DkS2mJrOCwzMCgGWfpKcaADllUizZkLCS soBtqFB3u+W604pwRRFt8Ac39jzzo1LySot2+Vc9d8snZVIPgn1d3j5uaLIEzVEpy0qJ 1Acw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZIZ8MVxdY/J49c7D99WtfVmFs8xsaWTWkpgUihv6ww0=; b=2bvlHwAg7B7WiHL+TlPnj1H8thgS4f9UmMRqeeTmS7vOxIgndatrLQWFDrkbjaLHwQ fh5WDiU1qOREHxC6firHNLoyO5DW23xB2GGb4bnpMruD130dFmxzUttlxtczhWJWZ0JC //J9BCu7gVe50laLRYPUot0YbltggJ2vZOlOBgxxKNq2Dc1FUBrloqz12BJbFmQmWIPL NdDI+OMNE0ZV+EHixVMOje//EkWzNdBYk3pg6GjXD1pDWINro0huYvI8VZntnPzGbTEI 1VjPUCQWSfKQAck86gX6DxL4seUWfczAfpMV91Z2NOj9L/ST8vH7ESQrVZDOZjmfC1gL 36dg== X-Gm-Message-State: AO0yUKXN0MFrmaTDS24o38qoOCw63qUeutTRqGnHM8txX158SbPK1pYy lrH6lVkYQJrkB5OKEkWf16/G2henVZcIChfWO4yl0STLoBNzRg== X-Google-Smtp-Source: AK7set+mXlPeTrKFY1ewsq5RyLmUQjPmC91A75KhwYKrP9IpCXOyQfXzAGsaBHxMgl7H6+lhkomECzBC2RtOPy5L8jE= X-Received: by 2002:a05:6808:206:b0:384:1f5f:d19e with SMTP id l6-20020a056808020600b003841f5fd19emr3459986oie.0.1677787094512; Thu, 02 Mar 2023 11:58:14 -0800 (PST) MIME-Version: 1.0 References: <0106914a-9eb5-22be-40d8-652cc88c827d@enterprisedb.com> <20230220143452.GM1653@telsasoft.com> In-Reply-To: From: David Rowley Date: Fri, 3 Mar 2023 08:58:02 +1300 Message-ID: Subject: Re: Add support for unit "B" to pg_size_pretty() To: Peter Eisentraut Cc: Justin Pryzby , pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 27 Feb 2023 at 21:34, Peter Eisentraut wrote: > > On 22.02.23 03:39, David Rowley wrote: > > I think you'll need to find another way to make the aliases work. > > Maybe another array with the name and an int to reference the > > corresponding index in size_pretty_units. > > Ok, here is a new patch with a separate table of aliases. (Might look > like overkill, but I think the "PiB" etc. example you had could actually > be a good use case for this as well.) I think I'd prefer to see the size_bytes_unit_alias struct have an index into size_pretty_units[] array. i.e: struct size_bytes_unit_alias { const char *alias; /* aliased unit name */ const int unit_index; /* corresponding size_pretty_units element */ }; then the pg_size_bytes code can be simplified to: /* If not found, look in the table of aliases */ if (unit->name == NULL) { for (const struct size_bytes_unit_alias *a = size_bytes_aliases; a->alias != NULL; a++) { if (pg_strcasecmp(strptr, a->alias) == 0) { unit = &size_pretty_units[a->unit_index]; break; } } } which saves having to have the additional and slower nested loop code. Apart from that, the patch looks fine. David