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 1whhkH-000NCv-2V for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 05:56:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whhkE-00BCcR-2y for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 05:56:23 +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.96) (envelope-from ) id 1whhkE-00BCcI-1w for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 05:56:23 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1whhkC-00000000Pnh-1GzN for pgsql-hackers@postgresql.org; Thu, 09 Jul 2026 05:56:23 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-69eb8b6bea8so694608eaf.3 for ; Wed, 08 Jul 2026 22:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783576579; cv=none; d=google.com; s=arc-20260327; b=aDs1lj7lKnc8ddCb1II1KjAHuXIcIBiflJ5US9G3YtVp14omfgm/c0FkgCmxQjN0UG 8dYyRuipaZ54nQ8Cj3hLivhmm5GQ32uLzuUVplVYRXYYChFYrbAqE+JEYjLYzsfqmneF Ah+YUrlB02ScoXX5CN00T0KJnSwDMoHJAtyi3oes+5FrxLOc7s2peQyFrT9kCiKLV8ck AQYGS6rAZpJ0D8R1wFb/XuRo31QMOfOEXAJ5jFts5mp5dBZLxFr457P8VJCvoZPABmrk oL1lPhOg8SioArKXdV5fUd1UuIHKP9u5fp6PjsObLgYhMqktXsc95zT20/7G57JCHXKX qvug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tEtK26tisUzksEe/DgzocJh93M0tr9OYGCUwemSRW68=; fh=iZXOkr7+UCSWZ0mQP2EpvoETTmwfG+diUYxDv1hCiZQ=; b=hJv1ALoWoxF5uP1WZH5XZ0HTGiqDUN/kM0ZHTjVi7SVAnPrSC3lODhb4wX2VVGxLPf yLUs72UzRqwAFWKq1BoN5y7XfExrgfLC1J3PO8C7IMvgczyiy5qwclZgvtsY/y5DrMNW +lk+QebrLwh/SDxZKwTffnSyfeMHfdoA700EhirEhFTATfBg2VIdhUDBUIzLsdvAlKP9 tKuiiz0wvSHYCqzZMsOBTot/prM/vFM7OAqujdqjDiIs8mKGMbzhHONw9JdYtHQSjfz6 WHfbTnDzaf7hAJoQnKCOIoEfKsMaiqaej2VD1w1/vA7idpNoHreKz3A20bncoPdM8AHU WOiw==; 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=20251104; t=1783576579; x=1784181379; darn=postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=tEtK26tisUzksEe/DgzocJh93M0tr9OYGCUwemSRW68=; b=g53B+KYeF0N6oTZkQYivZCUox6U2zACzhygs+pL57vqLR8qIqmbp0LRZLTDy7Ox1gs 8aw92NlwW1Y0g8oZgaTKmfpEdfY/CK1DZaksqIVpkPSkGEnjDFA7vT+ezWmt7DEmpxTS liiEUEcibdzl3tGwKGLV/WcrTUDfsID01IFJiA0lnHbxSUr1fG2Qp/BQG7+0twD1qINl ouWQ/JoQHilm3G8UIQx7oYUBaVW9g6JdXPEl72rt/M5CqY1h2VECGKB8j3yG3fTovQrO WK6U/OSkGRSuVlotqf5l4WHXi5EYt9SE5QJkIHMZWCOxn+zJBCQdiV7iNNmXCXc9Fi1i CRMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783576579; x=1784181379; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tEtK26tisUzksEe/DgzocJh93M0tr9OYGCUwemSRW68=; b=Y6B2DOHSOmmWbKhOWYP7lFPWirhImPFbjJVQMjtaMxlYw2th8occPIQX2ByMWftUsJ LQwjdGgyGoLltI/4Aph0b3KDEaNnVHXXQWhxyTEgcqwBVlz0Z0Gzx9u8EMG7w6qjbi0v aMO8w+o4T7ueER/04zDZmomsmp6gQ3XNGgYl6j7zjASfzNIbr6VphgwfuaN6MHVZCVvk JUp3Smx6JvIQmTLsarwyqV0EEdb0y7YZUMTQhJ/s5jOEW6XdejqoYESACQ3BmoLPuk7h 0BzjkYLla0iZyeDlkGI8OITJddxoaleaVl3fP6GpmpNKeFWUMTiOPTOZnMUYZc4gLRyc /QVw== X-Forwarded-Encrypted: i=1; AFNElJ+limE7xaQ1PgCrKBRxjmMu+QMeNbO6STxw6xgghttqPtO5YcqiJePcckvzm8hQK2bDAEgzcvi2eAEv44oo@postgresql.org X-Gm-Message-State: AOJu0YyL7ApPbveQeg4G2eK0x5nUTE1KPjCg+LDyg0GYZQ4pPwOzq0lG HRt23GI/45OuvsFiXDdYSD0TCm0Nn/rCqW/q4aMcrduorTWMGrnQ2HCN61/Rn/2MoWIPX/EQG+K XqNh9I1OzI3fWdqrrucdc72dRNHRwaE8= X-Gm-Gg: AfdE7cnDlqtuOzpns2NqfYmCvsZ9qZ+HOxste1OK3i2KFpmCWMUl5HT9gUdF1ctoLOV g3irOkRNAswkvJDgg3f82eX5kw/bkkzUcxjRvgAmKlcPZ27DwicNyQZX39eaasbbN9yMTkfGGFl TP0T85TlDYPHEdWCaTG271OBH4tFzRot0OCwljdf+lpmX/tcOJkXy/LfcWlK2b9XOiDEx4no+PF bcjc7nLomRFW2EL+D4XjLnqaaTVJ0+f/pz2y+OiQYfa0Ear4Qz3/Br0O9SamVfhGUL64XgwuGw8 wKslHu0iRrLP2Ax2N47kZ8SvjjtDBPY/dn4ffcW1PwRymE4BPPieg5uN23thwQ8kDf46VQ2onIR L7bu1ONb3uohRlv0MVSRMbOKL4V+dI6Gcrt3NrCtC3SHTk4yClqktWinWfqRrf/4HWg2ZWNAtUU hD0356Iu9ZjR2CcDg= X-Received: by 2002:a05:6820:f010:b0:6a1:43f0:35e with SMTP id 006d021491bc7-6a36d8972c0mr4540727eaf.12.1783576578610; Wed, 08 Jul 2026 22:56:18 -0700 (PDT) MIME-Version: 1.0 References: <20260704.162841.39857602849942465.ishii@postgresql.org> <20260706.150221.1117486145015185971.ishii@postgresql.org> In-Reply-To: From: jian he Date: Thu, 9 Jul 2026 13:55:41 +0800 X-Gm-Features: AUfX_mxAgwUqtgKThhAz6mmdehMI9oORJGqJRBoby4Gngqu85ZdIJ4wFwrOjHqc Message-ID: Subject: Re: Row pattern recognition To: assam258@gmail.com Cc: Tatsuo Ishii , pgsql-hackers@postgresql.org, zsolt.parragi@percona.com, sjjang112233@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com, david.g.johnston@gmail.com, peter@eisentraut.org, li.evan.chao@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 7, 2026 at 11:40=E2=80=AFAM Henson Choi wr= ote: > > That said, I don't think we should take it into the patch at this > stage. The current version has one proven defect: a plain > FIRST(expr, n) with n > 0 loses its forward reach. I added a test for > it -- "DEFINE A AS v > FIRST(v, 5)" in rpr_explain -- where the > baseline prints "Nav Mark Lookahead: 5" and the patch prints 0. The > query result is still correct (the mark is under-advanced, so it only > keeps extra rows), but the EXPLAIN is wrong and the tuplestore trim is > lost, so it is a regression against the baseline. > > The test will come with the next patch email I send, so you will have > it there to diff against. > The case you mentioned: PATTERN (A) DEFINE A AS v > FIRST(v, 5) is fixable easily, it was a mistake I made while refactoring visit_nav_exec to cut down the number of eval_nav_offset() calls. > More broadly, though, reshaping the offset handling this much right as > we are stabilizing for commit feels like the wrong time -- at this > point I would rather limit changes to minimal fixes for proven > defects. This is a worthwhile cleanup that deserves proper review > time, and it would be more valuable if it can be refined without that > pressure. > > So how about, once the current patch is verified and committed, we > pursue this as a separate follow-up? That refactor is the patch I posted in [1]. An excerpt from its commit mess= age: ``` Row pattern navigation (PREV/NEXT/FIRST/LAST and their compounds) resolves offsets (transforming an expression into an int64) in ExecInitExprRec, ExecEvalRPRNavSet, extract_const_offset and eval_define_offsets. Several places transform the same offset expression into an int64 -- that is too mu= ch. With the attached, a single place (ExecInitWindowAgg -> eval_define_offsets= ) handles this. ``` I think this belongs in the patchset now, rather than as a follow-up after = the main patch is committed. Computing the same offset in several places hurts readability and, as this bug shows, is error-prone; consolidating it into o= ne place makes the code easier to read for future reviewers. Committing the main patch and then posting a separate "make it readable" refactoring afterward feels weird to me. Refactoring now benefits everyone by significantly improving readability. Broadly, I'd defend patch [2] on the same grounds: it improves readability,= and The current patchset doesn't need code that complex. It may not be the most future-proof approach (I'm not certain) but given how complicated the whole patchset already is, making each part more readable is a clear win for reviewers. Let's improve readability now while we can. Even assuming the patch is committable today, there are still 9 months to refine it, so there's no rus= h that justifies skipping cleanups. Each refactor makes the code more readabl= e and easier for reviewers to follow, which benefits everyone. There won't be unlimited rounds of readability refactoring. Each refactor makes the code clearer. --------------------------------------------------- I hope the above is convincing. [1] https://www.postgresql.org/message-id/CACJufxFfMJAMc0R6g4f7Bwr47QDY%2BO= Br2vzqqMRbCzjdD9vR2g%40mail.gmail.com [2] https://postgr.es/m/CAAAe_zC6iN79qEOgD2TzLHxA8i4T9R3pYtn_5dsQV8FXn3cEcA= @mail.gmail.com -- jian https://www.enterprisedb.com/