Window Functions

From MemCP
Revision as of 11:59, 28 August 2026 by Wikiservice (talk | contribs) (Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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)