Window Functions: Difference between revisions

From MemCP
Jump to navigation Jump to search
(Created page with "← Back to Full SCM API documentation == stream_emit == invokes a streaming callback immediately; marks ordering-sensitive emission as an observable effect '''Allowed number of parameters:''' 2–2 <span id="parameters"></span> === Parameters === * '''emit''' (<code>func(value:any) -> any</code>): * '''value''' (<code>any</code>): <span id="returns"></span> === Returns === <code>any</code> == stream_window_reduce == applies OFFSET/LIMIT and a serial redu...")
 
(Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
 
Line 1: Line 1:
← Back to [[Full SCM API documentation]]
<!-- Copyright (C) 2026 Carl-Philip Haensch -->
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
 
<span id="window-functions"></span>
= Window Functions =
 
<!-- Generated from MemCP c42e19eba on 2026-08-27; do not edit manually. -->
<div class="mw-message-box mw-message-box-notice">Generated from MemCP commit <code>c42e19eba</code> on 27 August 2026. See [[Full SCM API documentation]].</div>
 
The '''Window Functions''' runtime helpers support ordered streaming plans. They emit complete producer values, apply bounded serial reductions, maintain ring-buffer frames, and flush pending window positions.
 
SQL users normally call <code>ROW_NUMBER</code>, <code>RANK</code>, <code>LEAD</code>, <code>LAG</code>, and related SQL functions rather than invoking these helpers directly. The planner may stream a frame or use an ordered-reduce computed column depending on ordering and reuse.


== stream_emit ==
== stream_emit ==
Line 10: Line 21:
=== Parameters ===
=== Parameters ===


* '''emit''' (<code>func(value:any) -&gt; any</code>):
* '''emit''' (<code>func</code>)
* '''value''' (<code>any</code>):
** '''Parameters'''
*** '''value''' (<code>any</code>)
** '''Returns'''
*** '''value''' (<code>any</code>)
* '''value''' (<code>any</code>)


<span id="returns"></span>
<span id="returns"></span>
=== Returns ===
=== Returns ===


<code>any</code>
* '''value''' (<code>any</code>)


== stream_window_reduce ==
== stream_window_reduce ==
Line 29: Line 44:
* '''offset''' (<code>number</code>): number of complete producer values to skip
* '''offset''' (<code>number</code>): number of complete producer values to skip
* '''limit''' (<code>number</code>): maximum values to reduce, or -1 for no limit
* '''limit''' (<code>number</code>): maximum values to reduce, or -1 for no limit
* '''reduce''' (<code>func(acc:any, value:any) -&gt; any</code>): serial accumulator over complete values
* '''reduce''' (<code>func</code>): serial accumulator over complete values
** '''Parameters'''
*** '''acc''' (<code>any</code>)
*** '''value''' (<code>any</code>)
** '''Returns'''
*** '''value''' (<code>any</code>)
* '''neutral''' (<code>any</code>): initial accumulator
* '''neutral''' (<code>any</code>): initial accumulator
* '''producer''' (<code>func(emit:func) -&gt; any</code>): nested streaming plan called with a one-value emit callback
* '''producer''' (<code>func</code>): nested streaming plan called with a one-value emit callback
** '''Parameters'''
*** '''emit''' (<code>func</code>): emits one complete value
**** '''Parameters'''
***** '''value''' (<code>any</code>)
**** '''Returns'''
***** '''result''' (<code>any</code>)
** '''Returns'''
*** '''value''' (<code>any</code>)


<span id="returns-1"></span>
<span id="returns-1"></span>
=== Returns ===
=== Returns ===


<code>any</code>
* '''value''' (<code>any</code>)


== window_mut ==
== window_mut ==
Line 48: Line 76:


* '''window''' (<code>list</code>): ring buffer accumulator
* '''window''' (<code>list</code>): ring buffer accumulator
* '''emit_fn''' (<code>func(values:any...) -&gt; any</code>): callback receiving all window values oldest-to-newest
* '''emit_fn''' (<code>func</code>): callback receiving all window values oldest-to-newest
** '''Parameters'''
*** '''values''' (<code>any</code>) ''(variadic)''
** '''Returns'''
*** '''value''' (<code>any</code>)
* '''vals''' (<code>list</code>): list of stride values to insert
* '''vals''' (<code>list</code>): list of stride values to insert


Line 54: Line 86:
=== Returns ===
=== Returns ===


<code>list</code>
* '''value''' (<code>list</code>)


== window_flush ==
== window_flush ==
Line 66: Line 98:


* '''window''' (<code>list</code>): ring buffer accumulator
* '''window''' (<code>list</code>): ring buffer accumulator
* '''emit_fn''' (<code>func(values:any...) -&gt; any</code>): callback receiving all window values oldest-to-newest
* '''emit_fn''' (<code>func</code>): callback receiving all window values oldest-to-newest
** '''Parameters'''
*** '''values''' (<code>any</code>) ''(variadic)''
** '''Returns'''
*** '''value''' (<code>any</code>)
* '''count''' (<code>number</code>): number of nil positions to shift in
* '''count''' (<code>number</code>): number of nil positions to shift in


Line 72: Line 108:
=== Returns ===
=== Returns ===


<code>nil</code>
* '''value''' (<code>nil</code>)


== show_processlist ==
== show_processlist ==
Line 88: Line 124:
=== Returns ===
=== Returns ===


<code>list</code>
* '''value''' (<code>list</code>)


== connection_id ==
== connection_id ==
Line 104: Line 140:
=== Returns ===
=== Returns ===


<code>int</code>
* '''value''' (<code>int</code>)


== kill_query ==
== kill_query ==
Line 120: Line 156:
=== Returns ===
=== Returns ===


<code>bool</code>
* '''value''' (<code>bool</code>)

Latest revision as of 11:59, 28 August 2026


Window Functions

Generated from MemCP commit c42e19eba on 27 August 2026. See Full SCM API documentation.

The Window Functions runtime helpers support ordered streaming plans. They emit complete producer values, apply bounded serial reductions, maintain ring-buffer frames, and flush pending window positions.

SQL users normally call ROW_NUMBER, RANK, LEAD, LAG, and related SQL functions rather than invoking these helpers directly. The planner may stream a frame or use an ordered-reduce computed column depending on ordering and reuse.

stream_emit

invokes a streaming callback immediately; marks ordering-sensitive emission as an observable effect

Allowed number of parameters: 2–2

Parameters

  • emit (func)
    • Parameters
      • value (any)
    • Returns
      • value (any)
  • value (any)

Returns

  • value (any)

stream_window_reduce

applies OFFSET/LIMIT and a serial reducer to complete values emitted by a nested streaming producer without collecting an intermediate relation

Allowed number of parameters: 5–5

Parameters

  • offset (number): number of complete producer values to skip
  • limit (number): maximum values to reduce, or -1 for no limit
  • reduce (func): serial accumulator over complete values
    • Parameters
      • acc (any)
      • value (any)
    • Returns
      • value (any)
  • neutral (any): initial accumulator
  • producer (func): nested streaming plan called with a one-value emit callback
    • Parameters
      • emit (func): emits one complete value
        • Parameters
          • value (any)
        • Returns
          • result (any)
    • Returns
      • value (any)

Returns

  • value (any)

window_mut

Ring buffer shift-insert for window functions. (window_mut window emit_fn vals) writes vals (a list of stride values) into the current slot, increments counter. If skip>0, decrements skip. Otherwise calls (emit_fn oldest_v0 oldest_v1 ... newest_v0 newest_v1) with all slot values ordered oldest-to-newest. Returns updated window.

Allowed number of parameters: 3–3

Parameters

  • window (list): ring buffer accumulator
  • emit_fn (func): callback receiving all window values oldest-to-newest
    • Parameters
      • values (any) (variadic)
    • Returns
      • value (any)
  • vals (list): list of stride values to insert

Returns

  • value (list)

window_flush

Flush remaining window buffer by shifting in nils. (window_flush window emit_fn count) shifts in count positions of nils, calling emit_fn for each displaced position. Returns nil.

Allowed number of parameters: 3–3

Parameters

  • window (list): ring buffer accumulator
  • emit_fn (func): callback receiving all window values oldest-to-newest
    • Parameters
      • values (any) (variadic)
    • Returns
      • value (any)
  • count (number): number of nil positions to shift in

Returns

  • value (nil)

show_processlist

returns a list of active sessions for SHOW [FULL] PROCESSLIST; pass true for full info

Allowed number of parameters: 0–1

Parameters

  • full (bool): if true, include full Info text (optional)

Returns

  • value (list)

connection_id

returns the process-list ID of the current session (MySQL CONNECTION_ID() equivalent)

Allowed number of parameters: 0–0

Parameters

This function has no parameters.

Returns

  • value (int)

kill_query

cancel the running query in session id; returns true if a query was killed

Allowed number of parameters: 1–1

Parameters

  • id (int): session ID from SHOW PROCESSLIST

Returns

  • value (bool)