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 1tDMUl-000AbD-6i for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2024 11:34:11 +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 1tDMUi-00CbKx-6s for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2024 11:34:08 +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 1tDMUh-00CbKp-QW for pgsql-general@lists.postgresql.org; Tue, 19 Nov 2024 11:34:08 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tDMUf-002jgp-Id for pgsql-general@lists.postgresql.org; Tue, 19 Nov 2024 11:34:07 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5ceca0ec4e7so865388a12.0 for ; Tue, 19 Nov 2024 03:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=cybertec.at; t=1732016044; x=1732620844; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=MN7UBbSiQ+3FVnou2DQn+rxZiF83LGjOBaa0TnpiZY4=; b=HoT5oScOBBm4EIPvV8/ec7CfkIvHS0uMaJBsULDoMZpo9xTTqHitbABt4MCkXGaQZR rlmgVXgqIOxuDJyUTDa4RuCyddO8UMclSyfnZG2tUu9xpJRx6QIZWz03cP0w7KwH2PJG vBPMRsXGiDhACTdEB28MMR++bX5Fli3FlLrBw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732016044; x=1732620844; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MN7UBbSiQ+3FVnou2DQn+rxZiF83LGjOBaa0TnpiZY4=; b=vY5ws+VFZ3TeY2XcVZTcfqfQArNXp93ZMvWS3nRzdxspc15RjRlOsS8yb96+z/y/vl DSCmjTl2aUT4Knl2n6egCjBQpd0t4L1iEY6SvWbbT8m9JbntTB2/3Dq43Tv9yroSsj8y ebO6oTEaGZypsqydK27UB0lLYOjXSm86H3MU40mzXK/zNqQJs6pA9cBOVAcX/ykt9GUX c7NgeWQevwAOic72vLl3WWsDrOlbvlg9Ub18wqy1ZUEdYp7SwQ1sC20Oxy47S1CH+Rye q2WsOqS9AEeAu5KAP/7AAOVRWu9RVyMz/aUlhdp9ZLSiajuZjGjExuA7YP7GqUpn0nU3 pZjg== X-Forwarded-Encrypted: i=1; AJvYcCXzh9x0YOWz8RpJGzPaJRZfGQ9GrvrzrRIBVzdLPaQwLuCKhh//OG+yp96Q8MZder9iadclW6N/FkL3DcrG@lists.postgresql.org X-Gm-Message-State: AOJu0Yy9EdtIMNB0/5d3G2AceXC+aapqa2UdKwmQ+EA4DKBa5exYmvpE uLPng4OktipkOR+CQ8xPy9jMrdOidmKhm+EnHwLquOd7V8+yDYEvqUIE4Js67oQ= X-Google-Smtp-Source: AGHT+IHXDXlUU1H6f101edzkP49RwF/riIVwJbxIi0VpWk5ey9IxNHsUnSuWJDCa5siSvFLVPZ0/dw== X-Received: by 2002:a05:6402:5216:b0:5cf:cb54:a0e7 with SMTP id 4fb4d7f45d1cf-5cfcb54a256mr5005022a12.30.1732016044530; Tue, 19 Nov 2024 03:34:04 -0800 (PST) Received: from localhost.localdomain ([178.250.162.186]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e0016b3sm647913666b.103.2024.11.19.03.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 03:34:04 -0800 (PST) Message-ID: Subject: Re: Functions and Indexes From: Laurenz Albe To: Moreno Andreo , pgsql-general@lists.postgresql.org Date: Tue, 19 Nov 2024 12:34:03 +0100 In-Reply-To: <14fa809c-a2b7-4d36-9382-d08a5df4718a@evolu-s.it> References: <2e36a2fe-b30f-46a5-937f-3b7d94e75cb6@evolu-s.it> <8dfd0bd5-87e5-4de7-9f60-8a680a32bc11@evolu-s.it> <61cb94a962667788c9c09107fa9937300e54d3cd.camel@cybertec.at> <14fa809c-a2b7-4d36-9382-d08a5df4718a@evolu-s.it> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-2.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2024-11-19 at 11:53 +0100, Moreno Andreo wrote: > > > What about if query becomes > > > SELECT foo1, foo2 FROM bar WHERE (POSITION(foo1 IN 'blah blah') >0) > > > > You could create an index like > >=20 > > =C2=A0=C2=A0=C2=A0 CREATE INDEX ON bar (position(foo1 IN 'blah blah')); > >=20 > > Alternatively, you could have a partial index: > >=20 > > =C2=A0=C2=A0=C2=A0 CREATE INDEX ON bar (foo1) INCLUDE (foo2) > > =C2=A0=C2=A0=C2=A0 WHERE position(foo1 IN 'blah blah') > 0; > > Interesting. Never seen this form, I'll look further on it. >=20 > I stumbled into > https://www.cybertec-postgresql.com/en/indexing-like-postgresql-oracle/ > and discovered text_pattern_ops. > I'm wondering if it can be of any use in my index, that should hold a=20 > WHERE condition with a combination of LIKE and the POSITION expression= =20 > above. > More docs to read ... :-) I don't think "text_pattern_ops" will help here - queries that use LIKE to search for a substring (LIKE '%string%') cannot make use of a b-tree index. Yours, Laurenz Albe