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 1vq1Gj-002u8d-2o for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 03:52:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vq1Fk-002JWu-0O for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 03:51:00 +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 1vq1Fj-002JWl-2Z for pgsql-hackers@lists.postgresql.org; Wed, 11 Feb 2026 03:51:00 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vq1Fg-0000000047T-1EqV for pgsql-hackers@postgresql.org; Wed, 11 Feb 2026 03:50:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=Lw8TsCs4nfD2Vi461Wdalm0P6o76l1Rj6rX+h/vzitE=; b=5CdxA3i0cnHCdfPp7fPd937c/B dJcpFm//k8Fp8yC4S7+1Ro2uaz+RMHh5rcFaZ1FETh4lw4wLukbjqyahcVd14T6hlU1EkvsquefKx lo+A5FPZ1JtWPSK2BA1xuvIdYKPamiW643D2KuG4Zxl+LeBiCKPF0tPmk7pbdhTyxaseZnSW+7tTx PIOg3mL0bB8JqzeOk0xdm4N+qpmY8yUWR7q3M27cDb/qKIEPsT2rtBk5Sj79veR6YaILtAe/eciN+ n3VGl8kR8hwjifhArEoCP+ETVykFhbXqCRtmDclfOazWe2Vh+OENPdjQ1F4g5GhuSRo5/e1FqAC1w KWII16lQ==; Received: from [2409:11:4120:300:ca0b:56e6:d6a:5858] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vq1FZ-000Ccn-0C; Wed, 11 Feb 2026 03:50:52 +0000 Date: Wed, 11 Feb 2026 12:50:32 +0900 (JST) Message-Id: <20260211.125032.1207789314761104094.ishii@postgresql.org> To: assam258@gmail.com, vik@postgresfriends.org, er@xs4all.nl, jacob.champion@enterprisedb.com Cc: david.g.johnston@gmail.com, vik@postgresfriends.org, er@xs4all.nl, peter@eisentraut.org, pgsql-hackers@postgresql.org Subject: Re: Row pattern recognition From: Tatsuo Ishii In-Reply-To: References: <20260209.190209.470246357440525054.ishii@postgresql.org> X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:ca0b:56e6:d6a:5858 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Henson, In my understanding RANGE/GROUPS are not allowed when RPR is defined. (See ISO/IEC 19075-5 section 6.10.2 "ROWS BETWEEN CURRENT ROW AND"). So proper fix would be to error out at the parse/analyze phase if RANGE/GROUPS are used when RPR is defined. Vik, Jaconb, Thoughts? Best regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp > Hi Ishii-san, > > During code review of nodeWindowAgg.c, I discovered that > update_reduced_frame() > can receive the same pos value repeatedly for RANGE/GROUPS frames. > > > ---------------------------------------------------------------------- > PATTERN DISCOVERED > ---------------------------------------------------------------------- > > For RANGE/GROUPS frames with peer rows (rows having the same ORDER BY > value): > > Data: id=1,2,3 all have val=10 (peer rows) > id=4,5 both have val=20 (peer rows) > > RANGE frame processing: > - id=1 processing: pos=0 (frameheadpos points to first peer) > - id=2 processing: pos=0 (same frameheadpos) > - id=3 processing: pos=0 (same frameheadpos) > - id=4 processing: pos=3 > - id=5 processing: pos=3 > > ROWS frames always have sequential pos values (0,1,2,3,4...), but > RANGE/GROUPS > can have repeated pos values (0,0,0,3,3...). > > > ---------------------------------------------------------------------- > CURRENT IMPLEMENTATION ISSUE > ---------------------------------------------------------------------- > > The current implementation appears to assume sequential processing only, > which > is valid for ROWS frames. Two specific issues found: > > 1. In update_reduced_frame(): > - The pos <= nfaLastProcessedRow check assumes "already processed pos > doesn't > need reprocessing", but RANGE/GROUPS require processing the same pos > multiple times. > > 2. In nfa_process_row(): > - Frame boundary calculation: ctxFrameEnd = matchStartRow + frameOffset > + 1 > - This adds frameOffset directly to row position, which works for ROWS > but > may be incorrect for RANGE (value-based) and GROUPS (group-based) > frames. > > > ---------------------------------------------------------------------- > TEST COVERAGE LIMITATION > ---------------------------------------------------------------------- > > The existing RANGE/GROUPS test cases in rpr_base.sql only cover simple > scenarios > that don't reach the frame end, which is why this issue wasn't detected. > > Most tests target ROWS frames, with only a small number testing RANGE/GROUPS > frames. > > > ---------------------------------------------------------------------- > PROPOSAL > ---------------------------------------------------------------------- > > Rather than directly modifying these functions, we should consider an > alternative approach for non-UNBOUNDED frames: > - Strictly respect the frame head position > - Minimize lower-level optimizations (absorption/pruning) > - Avoid creating subsequent contexts for limited reuse benefit > - For bounded frames, the benefit of context reuse across rows may be > limited > compared to UNBOUNDED frames where contexts can be reused extensively > - This would simplify RANGE/GROUPS handling at the cost of some optimization > > To implement this properly, we need to broaden our understanding of the > execution structure through code review of Window clauses and Aggregate > functions. > > Therefore, for this round of nodeWindowAgg.c review: > 1. Perform code simplification/refactoring for ROWS frames only > 2. Add FIXME comments to RANGE/GROUPS test cases > 3. Defer RANGE/GROUPS handling to a future phase > > There may be other issues beyond RANGE/GROUPS. > After this code review round is complete, I would like to regroup and > discuss > the direction forward. > > Best regards, > Henson