Skip to content

Flaky PG Wire with Window function error on demo query #5989

@nwoolmer

Description

@nwoolmer

To reproduce

Error originating from demo:

2025-07-25T10:45:04.830587Z E i.q.g.e.QueryProgress err [id=3890570, sql=`declare
  @symbol := 'BTC-USDT'
WITH price_changes AS (
    SELECT
        timestamp,
        symbol,
        close,
        close - prev_close price_change
    FROM (
      SELECT
          timestamp,
          symbol,
          price as close,
          LAG(price) OVER (PARTITION BY symbol ORDER BY timestamp) AS prev_close
      FROM trades_latest_1d
      WHERE timestamp BETWEEN '2025-06-25T10:45:04.762Z' AND '2025-07-25T10:45:04.762Z'
      AND symbol = @symbol AND side = 'buy'
    )
),
gains_losses AS (
    SELECT
        timestamp,
        symbol,
        close,
        CASE WHEN price_change > 0 THEN price_change ELSE 0 END AS gain,
        CASE WHEN price_change < 0 THEN ABS(price_change) ELSE 0 END AS loss
    FROM price_changes
),

avg_gains_losses AS (
    SELECT
        timestamp,
        symbol,
        close,
        AVG(gain) OVER (PARTITION BY symbol ORDER BY timestamp ROWS BETWEEN 13 PRECEDING AND C
URRENT ROW) AS avg_gain,
        AVG(loss) OVER (PARTITION BY symbol ORDER BY timestamp ROWS BETWEEN 13 PRECEDING AND C
URRENT ROW) AS avg_loss
    FROM gains_losses
)

SELECT
    timestamp as time,
    symbol,
    CASE
        WHEN avg_loss = 0 THEN 100
        ELSE 100 - (100 / (1 + (avg_gain / NULLIF(avg_loss, 0))))
    END AS rsi_14
FROM avg_gains_losses
ORDER BY timestamp;`


java.lang.AssertionError^M
        at io.questdb.cairo.vm.MemoryCARWImpl.checkAndExtend(MemoryCARWImpl.java:170)^M
        at io.questdb.cairo.vm.MemoryCARWImpl.appendAddressFor(MemoryCARWImpl.java:66)^M
        at io.questdb.griffin.engine.functions.window.AvgDoubleWindowFunctionFactory$AvgOverPa
rtitionRowsFrameFunction.computeNext(AvgDoubleWindowFunctionFactory.java:743)^M
        at io.questdb.griffin.engine.window.WindowRecordCursorFactory$WindowRecordCursor.hasNe
xt(WindowRecordCursorFactory.java:173)^M
        at io.questdb.griffin.engine.table.VirtualFunctionRecordCursor.hasNext(VirtualFunction
RecordCursor.java:101)^M
        at io.questdb.griffin.engine.QueryProgress$RegisteredRecordCursor.hasNext(QueryProgres
s.java:419)^M
        at io.questdb.cutlass.pgwire.modern.PGPipelineEntry.outCursor(PGPipelineEntry.java:214
0)^M
        at io.questdb.cutlass.pgwire.modern.PGPipelineEntry.outCursor(PGPipelineEntry.java:211
6)^M
        at io.questdb.cutlass.pgwire.modern.PGPipelineEntry.msgSync(PGPipelineEntry.java:804)^
M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.syncPipeline(PGConnectio
nContextModern.java:1422)^M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.msgSync0(PGConnectionCon
textModern.java:1181)^M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.msgSync(PGConnectionCont
extModern.java:1177)^M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.msgQuery(PGConnectionCon
textModern.java:1150)^M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.parseMessage(PGConnectio
nContextModern.java:1282)^M
        at io.questdb.cutlass.pgwire.modern.PGConnectionContextModern.handleClientOperation(PG
ConnectionContextModern.java:462)^M
        at io.questdb.cutlass.pgwire.modern.PGWireServerModern$1.lambda$$0(PGWireServerModern.
java:105)^M
        at io.questdb.network.AbstractIODispatcher.processIOQueue(AbstractIODispatcher.java:21
6)^M
        at io.questdb.cutlass.pgwire.modern.PGWireServerModern$1.run(PGWireServerModern.java:1
36)^M
        at io.questdb.mp.Worker.run(Worker.java:152)^M
]^M

QuestDB version:

9.0.1-SNAPSHOT

OS, in case of Docker specify Docker and the Host OS:

N/A

File System, in case of Docker specify Host File System:

N/A

Full Name:

Nick Woolmer

Affiliation:

QuestDB

Have you followed Linux, MacOs kernel configuration steps to increase Maximum open files and Maximum virtual memory areas limit?

  • Yes, I have

Additional context

No response

Metadata

Metadata

Assignees

Labels

BugIncorrect or unexpected behaviorPG-ModernPostgres WireIssues or changes relating to Postgres wire protocolinternal

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions