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.96) (envelope-from ) id 1vy0oY-00HLRx-2Z for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Mar 2026 04:59:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vy0oV-00FyLO-32 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Mar 2026 04:59:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vy0oV-00FyLF-1j for pgsql-hackers@lists.postgresql.org; Thu, 05 Mar 2026 04:59:56 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vy0oT-00000000U3E-2FsN for pgsql-hackers@postgresql.org; Thu, 05 Mar 2026 04:59:55 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-c738a4231a2so234604a12.2 for ; Wed, 04 Mar 2026 20:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772686793; cv=none; d=google.com; s=arc-20240605; b=aT8FggYyv2teGqX+jKFibX0pxzZa+FCmPKLHI4EGelTa94bDUTZBwdiio7N4uVmEdN 0+e+EvzGfcHfVID/3sIpZ+kqPA80TAnz34mXRnJM6tP+YTvaUeCXAlHvlKL7OxprGhwF TwYgw5MnAIQSgKhl5hLTgdF2JeelLkXz7gJc7JfZRz6m7Q6z8FumjPCK4gaumMZiq5GR sfHP9bj3+d1h/agCcU47DwKvP4v4+ZYZ2566xegPqV5vHqbYnH3Dsi14HqVt0FtL9DIU GcqY+VBuuiDPlRPlGPPKunHJ2Ay6FDZ2sCnY5kBiV8So6dYslMSzKfcCSaHzxbe54Ror V0GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:dkim-signature; bh=Xg82nG2+1xvr72/Q+8b2ghjhXjcQEC1XZZHTeOiTvlQ=; fh=U+B1ClYdx9Z6EmANzT1bTn6/R6+u5lRXH9oIAWVnSNU=; b=aS9EuzMske3nXaYfxDKL8WrY2Li0Mltj7XyqQR7riHUjZryG1tHgASENW/Ri3opfc2 RhoIggHWzfdao6/ml7ry6vjiTh3CyK9DF7yqvJN0uwCsAaZlby0kwsrxqxp5W/7lc3f5 QLRuI4Gnbjbho3O/JYUWbC7ztLkzc7dPJWhGNoYJgUwquGNKH0vUqhugOxK9cRBhT32D KK2dp1d547g0V02RwFym5FhtNvExhoDkXhWXbm404q/9vhioL+4ygVqv73zf1cTPE6+j upIHmhwLrIA0MXYi/5jiSTF4J9Wgeu34HqXlufrL38DDKSK1u4f3KwZki4r6B5JOgsRH SJJg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772686793; x=1773291593; darn=postgresql.org; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Xg82nG2+1xvr72/Q+8b2ghjhXjcQEC1XZZHTeOiTvlQ=; b=XjtMl5W7MaLgGiccBSL3QyBTzwT4wuB/+4zGnN9GbGLBUnmw7yhiRSe05qv94D4DLz qvomeub6JKtYesLXUkTU1zsca9DOsZOAtsvYzG+wz2F+v3UVXAc7R4fomVT7LWCb4Bqk Pp+lPCqOIj9zgUW22tjEYJd+p4lZJPspCiH6v4vI/6eEcxdy/qv/sWNdk6X8O6wG0O6Y mvF2Hz2grXopj2DrK7HZDwHQApvDOSgmP3UjZ8L1yCQj53/jxydVSr24blEDthdTiZvR UE6XkEqeZpvCSyHv5jbGM8ZcV9ySQmCfXdhZOHIHlySI7SedCRXjofEkVP95OTJHCq/D 0Sxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772686793; x=1773291593; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Xg82nG2+1xvr72/Q+8b2ghjhXjcQEC1XZZHTeOiTvlQ=; b=RCbF+Nt1V+bhhnCLBKjRTcZ4Uu0toT/ZxV/WRmwqo3kP88kJs7/n5aPCXLFVs6w51N rSiVbMZ0+yLtmzlQ7hgcTfsveqMgP2f3zu5GO6/kqi24WEmWCb14d1IlppDUw00lBsu5 WGBcDDn3lf6iwa6Er52EWdY25HOC9LqmixWk1q83gTNw1ZT03eVVNpPSXb76sT6SlTAJ 7I9MWXTkK3c1splFbwdZbWzabHRjUiN4Dcln7k1h2SU3jFWTTTVua2UrUyQX+Ls1/e1v P3l54IiRg1xjSnrKfJRXk+/wHBtjCXEcmNamFyAZ3s+GY06+K670snf1xXqD0MKI9VUy r4+g== X-Forwarded-Encrypted: i=1; AJvYcCW6la1mHfTFJ2K9Hg5FDBx2AYDRfrbuuvQC41PCk3NjyRbvaC1jNh0P9i+BW4W9XTA+TM5DGDZ7RWIlYIbg@postgresql.org X-Gm-Message-State: AOJu0Yx8xyHkGhMhEK3+UGSHMwqyt6PJBRRbqjgGKjBdRKllSewyM5rG Objlneqxa6eVv62QMZNdC2Vdpzh9JzLFLXQfUi0ezgQajzOXxLpC8zHnVLtdbHMw3i5/2HmQYN/ cpkA7iPJQVHsDehTiXK2eQyUhCGAQ2L8= X-Gm-Gg: ATEYQzyjKCBuoPB84jdT7tCGg1tJ6stsru7e8LCwbdWlCcaIa2bz7ABudjcZCr1AdPs upOqjNbZFLJWzZEMx7woNOLTaQhjN+mX0SVZ9d7d+kvrXKNdirhcHUlHy6HF5JGZHl113EXdMt7 yT8UEA2jVnfMWjMDHHRe39WfNmG9jSUDXhFu0iQAFeyW/t6QqZ4rZ1aemelIs9l0NhgbepNFN/s aMyHOBOSZYzKwTwXY24kLliRG7AT/wsOGflAhNFdqciIXrW1ojrdMJf9PepTIZVtsRsunyA1FEu ahkfprOKT7XIY5XgRA6YxeBkCpVwOHaXUelh98piIdyfDT3a+A== X-Received: by 2002:a17:902:d54b:b0:2aa:d5e5:b136 with SMTP id d9443c01a7336-2ae6ab22874mr54340035ad.38.1772686792622; Wed, 04 Mar 2026 20:59:52 -0800 (PST) MIME-Version: 1.0 References: <20260302.141823.129040280886273031.ishii@postgresql.org> <20260304.162450.1463961082114305353.ishii@postgresql.org> <20260304.171203.445020956605509539.ishii@postgresql.org> In-Reply-To: Reply-To: assam258@gmail.com From: Henson Choi Date: Thu, 5 Mar 2026 13:59:41 +0900 X-Gm-Features: AaiRm52m2_3PDSOLsUnGqKABWXsPZhTWAFcIQ1l0Ll0UAcbgFUiTZEe92u82RpA Message-ID: Subject: Re: Row pattern recognition To: =?UTF-8?B?7J6l7ISx7KSA?= , Tatsuo Ishii Cc: vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, pgsql-hackers@postgresql.org Content-Type: multipart/alternative; boundary="000000000000928530064c3fce38" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000928530064c3fce38 Content-Type: text/plain; charset="UTF-8" Hi Tatsuo, PostgreSQL bug: zero-min reluctant quantifier > > During cross-validation a PostgreSQL bug was discovered involving > reluctant quantifiers whose minimum repetition is 0. > > Example pattern: > > PATTERN (A*?) > DEFINE A AS val > 0 > > Result comparison: > > pattern PostgreSQL (cnt) Oracle (cnt) > A*? 1,1,1 0,0,0 > A?? 1,1,1 0,0,0 > A+? 1,1,1 1,1,1 > > For reluctant quantifiers with min=0 (such as *? and ??), PostgreSQL > always consumes at least one row, while Oracle allows a zero-length > match. When min>=1 (e.g., A+?), both systems behave the same. > This is indeed a bug. Thanks SugJun for finding it. I'll fix this in the next patch. Design difference: unused DEFINE variables > > Example: > > PATTERN (A+) > DEFINE A AS id > 0, B AS id > 5 > > PostgreSQL executes the query successfully and ignores the unused > variable B. > > Oracle raises: > > ORA-62503: illegal variable definition > Currently PostgreSQL silently removes unused DEFINE variables during optimization. Do you think we should raise an error instead, as Oracle does? > Oracle limitations observed > > > Bounded quantifier limit > > A{200} -> works > A{201} -> ORA-62518 > > Oracle appears to limit the upper bound of bounded quantifiers to 200, > while PostgreSQL does not impose this restriction. > I don't think we need to impose an artificial limit like Oracle's 200. What do you think? > Nested nullable quantifiers > > Examples: > > (A*)* > (A*)+ > (((A)*)*)* > > (A?|B){1,2} > ((A?){2,3}){2,3} > (A?){n,m} > (A? B?){2,3} > > Oracle raises: > > ORA-62513 > > when a nullable subpattern is wrapped by an outer quantifier, while > PostgreSQL executes these patterns successfully. > This seems like an Oracle limitation rather than a standard requirement. Best regards, Henson > --000000000000928530064c3fce38 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tatsuo,

PostgreSQL bug: zero-min reluctant quant= ifier

During cross-validation a PostgreSQL bug was discovered involv= ing
reluctant quantifiers whose minimum repetition is 0.

Example = pattern:

=C2=A0 PATTERN (A*?)
=C2=A0 DEFINE A AS val > 0
Result comparison:

pattern =C2=A0 PostgreSQL (cnt) =C2=A0 Oracle (= cnt)
A*? =C2=A0 =C2=A0 =C2=A0 1,1,1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A00,0,0
A?? =C2=A0 =C2=A0 =C2=A0 1,1,1 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A00,0,0
A+? =C2=A0 =C2=A0 =C2=A0 1,1,1 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A01,1,1

For reluctant quantif= iers with min=3D0 (such as *? and ??), PostgreSQL
always consumes at lea= st one row, while Oracle allows a zero-length
match. When min>=3D1 (e= .g., A+?), both systems behave the same.

This is indeed a bug. Thanks SugJun for finding it. I'll fix th= is in
the next patch.

Design difference: unused DEFINE variables

Example:

=C2= =A0 PATTERN (A+)
=C2=A0 DEFINE A AS id > 0, B AS id > 5

Pos= tgreSQL executes the query successfully and ignores the unused
variable = B.

Oracle raises:

=C2=A0 ORA-62503: illegal variable definiti= on

Currently PostgreSQL silently = removes unused DEFINE variables during
optimization. Do you think we sho= uld raise an error instead, as Oracle
does?
=C2=A0
Oracle limitations observed


Boun= ded quantifier limit

A{200} =C2=A0-> works
A{201} =C2=A0-> = ORA-62518

Oracle appears to limit the upper bound of bounded quantif= iers to 200,
while PostgreSQL does not impose this restriction.

I don't think we need to impose an ar= tificial limit like Oracle's 200.
What do you think?
= =C2=A0
Nested nullable quantifiers
Examples:

=C2=A0 (A*)*
=C2=A0 (A*)+
=C2=A0 (((A)*)*)*
=C2=A0 (A?|B){1,2}
=C2=A0 ((A?){2,3}){2,3}
=C2=A0 (A?){n,m}
= =C2=A0 (A? B?){2,3}

Oracle raises:

=C2=A0 ORA-62513

wh= en a nullable subpattern is wrapped by an outer quantifier, while
Postgr= eSQL executes these patterns successfully.

<= /div>
This seems like an Oracle limitation rather than a standard requi= rement.

Best regards,
Henson
--000000000000928530064c3fce38--