↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

54001 \u2014 statement_too_complex

语句过于复杂,超出 grouping set 或栈深度上限。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Program Limit Exceeded
condition name
statement_too_complex
lang
en
sqlstate
54001

版本定义 PG 18

54001

速览 {#at-a-glance}

54001 覆盖超过规划器、解析器或执行栈限制的语句。固定路径包括 4096 个 grouping set 上限和 max_stack_depth 检查。

含义 {#meaning}

源码区分结构性查询上限 too many grouping sets present (maximum 4096) 与递归执行深度 stack depth limit exceeded,后者 hint 指向 max_stack_depth。两者修复不同。

诊断 {#diagnosis}

保留消息和阶段:grouping sets 应统计生成数量并简化查询;stack depth 应检查递归 SQL/函数展开,并在改设置前比较平台栈限制。

处理 {#response}

重写或拆分结构过大的语句;stack depth 应先消除意外递归或减少嵌套,仅在确认操作系统栈允许时调整 max_stack_depth,再验证重写后的语句。显式事务中若发生此 ERROR,重试前执行 ROLLBACK 或 ROLLBACK TO SAVEPOINT;自动提交只有在语句或 stack setting 修正后才能重试。GUC 的 rlimit 检查会在 SET 或配置值校验时比较平台栈上限;若 SET 失败,仍按发起它的事务上下文恢复。

版本 {#versions}

锁定目录从 7.4 记录;引用解析器和栈深度路径来自 PostgreSQL 18.6,未强制触发限制。

相关 {#related}

54000、54011、42601

来源 {#sources}

src/backend/parser/parse_agg.c#L1166-L1172

src/backend/utils/misc/stack_depth.c#L100-L105

src/backend/utils/misc/stack_depth.c#L156-L168

结构化证据记录保存固定消息以及源码/运行边界。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "54001 is statement_too_complex in SQLSTATE Class 54."
}
claims · resolved-paths
{
  "claim_id": "resolved-paths",
  "limits": "Source confirmation is not natural runtime.",
  "method": "Read complete fixed source contexts.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.path.1",
    "src.path.2"
  ],
  "statement": "The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described."
}
claims · stack-platform-guard
{
  "claim_id": "stack-platform-guard",
  "limits": "",
  "method": "Read the complete stack-depth error and GUC check hooks.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.path.1",
    "src.path.2"
  ],
  "statement": "The max_stack_depth GUC check rejects a value above the platform stack rlimit and points to increasing the platform limit, while recursive checks emit 54001 before stack overflow."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 54001 from 7.4; that boundary does not prove exact implementation introduction."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.0",
    "primary_template": "too many grouping sets present (maximum 4096)",
    "severity_source": "ERROR",
    "sources": [
      "src.path.0"
    ],
    "sqlstate": "54001"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.0"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "too many grouping sets present (maximum 4096)",
      "position": 0,
      "role": "",
      "template": "too many grouping sets present (maximum 4096)"
    }
  ]
}
messages · message.1
{
  "limits": "",
  "message_id": "message.1",
  "path": "",
  "position": 1,
  "raw": {
    "hint_template": "Increase the configuration parameter \"max_stack_depth\" (currently %dkB), after ensuring the platform stack depth limit is adequate.",
    "id": "message.1",
    "primary_template": "stack depth limit exceeded",
    "severity_source": "ERROR",
    "sources": [
      "src.path.1"
    ],
    "sqlstate": "54001"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.1"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "stack depth limit exceeded",
      "position": 0,
      "role": "",
      "template": "stack depth limit exceeded"
    },
    {
      "kind": "hint",
      "literal": "Increase the configuration parameter \"max_stack_depth\" (currently kB), after ensuring the platform stack depth limit is adequate.",
      "position": 1,
      "role": "",
      "template": "Increase the configuration parameter \"max_stack_depth\" (currently %dkB), after ensuring the platform stack depth limit is adequate."
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L417"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/parser/parse_agg.c",
  "position": 1,
  "sha256": "6e80a805fddbfc9c7e0f3047b348bf992a20c99f16ce7fee89c7067753027f72",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_agg.c#L1166"
}
sources · src.path.1
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/misc/stack_depth.c",
  "position": 2,
  "sha256": "ed87e94a4f73600983230aca3a4c1869d3b9cbb7c83ec36a6bbd7e403925e920",
  "source_id": "src.path.1",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/misc/stack_depth.c#L100"
}
sources · src.path.2
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/misc/stack_depth.c",
  "position": 3,
  "sha256": "ed87e94a4f73600983230aca3a4c1869d3b9cbb7c83ec36a6bbd7e403925e920",
  "source_id": "src.path.2",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/misc/stack_depth.c#L156"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:93ffc7497d2d56bc345c23ed69b07466e629a4a9c3001ce85644a43ab1d151ef

正文语言: zh-Hans · english-manuals:93ffc7497d2d56bc345c23ed69b07466e629a4a9c3001ce85644a43ab1d151ef