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 1tmbfK-0081OB-KH for pgsql-general@arkaria.postgresql.org; Mon, 24 Feb 2025 16:50:47 +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 1tmbfI-0054LA-H7 for pgsql-general@arkaria.postgresql.org; Mon, 24 Feb 2025 16:50:44 +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 1tmbfI-0054L1-1L for pgsql-general@lists.postgresql.org; Mon, 24 Feb 2025 16:50:44 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tmbfF-000ZNj-1E for pgsql-general@lists.postgresql.org; Mon, 24 Feb 2025 16:50:43 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-2bd2218ba4fso828027fac.1 for ; Mon, 24 Feb 2025 08:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740415840; x=1741020640; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3SdXFiycJ9Whc+uIzJxEl07gg6VH+KQwqpJlXTWL+wA=; b=C8+DKvp+I7CI5MHNn0e9Z7QfWNkJF3B3O77XScOv0qQr3qKxqBM6ZHN9YvXlHl9EpZ mkub76uukBAIHRvfOd+OkMoBjOIqdDJmEbXzq7gJ5KdVJ5I9WDdqjAVWzD/xuBEq9+Zc jap37X1eRD7NKe7o7meJbi5cUT/PDTUPBo4qAx73zdV4IGKpmdRr24ZLW3AjHBf+Cg3N Z575jLoopfmpAVVzCp546hAiDvEsVg1OKgAX3lb+l6XZXgFfoaKY18dYy3heUaUwMt+g mOAwhDJI+tEjXVdUIw9yhxB1d/qFPYcvjF05hjuP3ICabGRqwUeU4YhpFigmmw9TQYZh yLwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740415840; x=1741020640; 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=3SdXFiycJ9Whc+uIzJxEl07gg6VH+KQwqpJlXTWL+wA=; b=VRDgws2vAYXVR/N5I0es0nk3xkElf9+1QY22QeXzIGQohLCivYjlFvWXuH2KlbsEdt qt9fILTiXdzTPNNCtdJzNPorxVlE1UVC5gLoXtM8VNPKp+UosMGFRP9NJ6z3wthkNVR6 /z4Za6llR9PKk7qrvK0dosR4gF1XydRmsAyh+Sq0/J/G+AyzMSVnz8JF5FIpSAKskUwu h0wOPrHxLK+cJbChcNAJVC/SI5N8sDEwxkLZSNrhgmnrV3APuLRgnKI9ajIkRebw8AZ1 BbWJGQLxlr85OvDkS+smKj1wZGlSQwZgWami7gY5ZcWGwQdVLaJQiWXYUIU/JPBRCpDi 0yBg== X-Gm-Message-State: AOJu0YwMUUg69RO7lk6xVKElgo2Az3IW+8Zh1YFX6sWpga3BCiNnAItB Wob1g0DA1Dc7mgr7Sl54qXuuh3KNrzeG764Px+YFPCshr5WNKqZf/3Tg9IExn1YUU2b9dNEYtax WG3DD3ntpx0amHlIauo+Ytxrxojc= X-Gm-Gg: ASbGncsXNrmvzFKCU1WdYs7F302b5WZ/zQLWUOzg4hUuMfKwen2XttylJdSwD5ATCKk Pc0zL5Bim2Og+pH6pIeHbJtR0kXuGue7nyVjOui8dVrhccG9KmZ+XM4YbX1TUU34sZlaZ7oh+14 aRYIxJx+BR5Q== X-Google-Smtp-Source: AGHT+IEn5+tgyAhTmCzyTDwDZIzmcMF1vcArd123OHnvOR1p0yfyH+bw10FNDjSqsohQnfb7N5DToTI01mL7MQdUcU0= X-Received: by 2002:a05:6808:1a0d:b0:3f4:9e6:fda with SMTP id 5614622812f47-3f425a658b8mr10925206b6e.1.1740415839984; Mon, 24 Feb 2025 08:50:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dominique Devienne Date: Mon, 24 Feb 2025 17:50:24 +0100 X-Gm-Features: AWEUYZkRM4YCPPatITWkF4aV_2F8fr332mmius2u0mhrwzL9gYuILMZ0beuu_c0 Message-ID: Subject: Re: Keep specialized query pairs, or use single more general but more complex one To: Greg Sabino Mullane Cc: pgsql-general@lists.postgresql.org, andrew@tao11.riddles.org.uk Content-Type: multipart/alternative; boundary="000000000000e7660f062ee62346" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e7660f062ee62346 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 24, 2025 at 5:39=E2=80=AFPM Greg Sabino Mullane wrote: > On Mon, Feb 24, 2025 at 4:46=E2=80=AFAM Dominique Devienne > wrote: > >> But now we have a new requirement, for "fuzzy find". I.e. the client can >> ask for names >> which are not the exact in-DB names, but also aliases of those names. >> > ... > >> join unnest($3::text[]) with ordinality as aliases(name, ord) on c.name >> =3D aliases.name >> > > I'm not seeing how this is supposed to work, if these aliases are not in > the database somewhere. > Maybe an example? How does "Alli" get mapped to a c.name of "Allison"? > They may be stored in the DB somewhere one day, but aliases are session-specific (not my design...), and we're introducing them first managed in the client C++ code, instead of in TEMP tables later perhaps. Client requests child named "Allison". There's no such row. Current simple query return no row. We lookup whether there's a list of aliases for "Allison". If there are, we send them in $3 as an array of string (e.g. ['All', 'Alli', ...], and the first one matching (thanks to order by ord limit 1) is returned, if any. This works. We already have unit tests for that. That not the question. The questions are about plan quality/performance of the complex query compared to the simpler one. If planning of unnest+order by ordinal+limit 1 recognized as a special case= ? Does the join order matter with unnest? These kind of things, which are above my pay grade I'm afraid... --DD --000000000000e7660f062ee62346 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Feb 24, 2025 at 5:39=E2=80=AFPM G= reg Sabino Mullane <htamfids@gmail= .com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">

They may be stored in the DB somewhere one day, but a= liases are session-specific (not my design...),
and we're int= roducing them first managed in the client C++ code, instead of in TEMP tabl= es later perhaps.

Client requests child named &quo= t;Allison". There's no such row. Current simple query return no ro= w.
We lookup whether there's a list of aliases for "Alli= son". If there are, we send them in $3 as an array
of string= (e.g. ['All', 'Alli', ...], and the first one matching (th= anks to order by ord limit 1) is returned, if any.

This works. We already have unit tests for that. That not the question.
The questions are about plan quality/performance of the complex que= ry compared to the simpler one.
If planning of unnest+order by or= dinal+limit 1 recognized as a special case?
Does the join order m= atter with unnest?
These kind of things, which are above my pay g= rade I'm afraid... --DD

--000000000000e7660f062ee62346--