[YSQL] Plain aggregate crashes the tserver while computing a custom definition of sum in DocDB
Author: mangalaman93Created Sep 29, 2026Updated Sep 29, 2026
Labelskind/bugarea/ysqlpriority/mediumstatus/awaiting-triage
Jira Link: DB-23894
Description
Commit: master 93d76e04734
A custom defined sum aggregate must not be pushed down to DocDB while computing a plain aggregate
CREATE SCHEMA gp_custom;
CREATE FUNCTION gp_custom.sum_sfunc(int, int) RETURNS int
LANGUAGE sql IMMUTABLE AS 'SELECT $1 + 1000 * $2';
CREATE AGGREGATE gp_custom.sum(int) (
sfunc = gp_custom.sum_sfunc,
stype = int,
initcond = '0'
);
CREATE TABLE t (k int, v int, PRIMARY KEY (k ASC, v ASC));
INSERT INTO t VALUES (1, 2), (1, 3), (2, 4);On YugabyteDB, it says partial aggregate true:
yugabyte=# EXPLAIN (COSTS OFF) SELECT gp_custom.sum(v) FROM t;
QUERY PLAN
---------------------------------
Finalize Aggregate
-> Seq Scan on t
Partial Aggregate: true
(3 rows)and running the query, it errors out:
yugabyte=# SELECT gp_custom.sum(v) FROM t;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.Strack Trace
==> /Users/aman.mangal/ybdata/node1/logs/tserver/postgresql-2026-09-29_104627.log <==
2026-09-29 10:48:04.686 IST [68551] LOG: received critical signal 11
2026-09-29 10:48:04.686 IST [68551] DETAIL: The backend received signal 11.
2026-09-29 10:48:04.686 IST [68551] BACKTRACE:
@ 0x1051590d8 YbCriticalSignalHandler
@ 0x1856d5744 _sigtramp
@ 0x106c695a8 yb::pggate::(anonymous namespace)::PgNumericColumnRef<>::SetValue()
@ 0x106c593d8 yb::pggate::DocResult::WritePgTuple()
@ 0x106c59c2c yb::pggate::PgDocOpFetchStream::GetNextRow()
@ 0x106c384e8 yb::pggate::PgDml::Fetch()
@ 0x106c87c88 yb::pggate::PgApiImpl::DmlFetch()
@ 0x106cfca44 YBCPgDmlFetch
@ 0x104dbde80 ybFetchNext
@ 0x104f47a88 YbSeqNext
@ 0x104f79d08 fetch_input_tuple
@ 0x104f77a90 ExecAgg
@ 0x104f5fd80 standard_ExecutorRun
@ 0x10bb31a40 pgss_ExecutorRun
@ 0x10bb627b0 ybpgm_ExecutorRun
@ 0x10bb76834 pgaudit_ExecutorRun_hook
@ 0x10531d2f0 yb_ash_ExecutorRun
@ 0x10532f86c yb_qpm_ExecutorRun
@ 0x105165eac PortalRunSelect
@ 0x1051659d8 PortalRun
@ 0x10516225c yb_exec_simple_query_impl
@ 0x105162990 yb_exec_query_wrapper_one_attempt
@ 0x10515dc6c PostgresMain
@ 0x1050a20d4 BackendRun
@ 0x10509f9b4 ServerLoop
@ 0x10509b974 PostmasterMain
@ 0x104fd11c8 PostgresServerProcessMain
@ 0x104fd0ebc main
@ 0x1853004e4 startOn postgres, it return 9000 as expected.
This happens because, YB pushes down the aggregate computation to DocDB but DocDB does not understand the custom definition of sum.
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
- I confirm this issue does not contain any sensitive information.
Source: yugabyte/yugabyte-db