# 02000 — no_data

> PostgreSQL SQLSTATE 02000 表示无数据条件；PostgreSQL 18.6 在 amcheck 有 DEBUG 诊断，但不是每个零行 SELECT 都会抛出它。
---

# 02000 — no_data

## 速览 {#at-a-glance}

`02000` 在 18.6 的 `contrib/amcheck/verify_nbtree.c` 中有确认的 `DEBUG1`/`DEBUG2` 内部索引检查路径。下面详列的三个组都确认是 `DEBUG1`；这些诊断不同于普通查询无行，也不是通用客户端错误。

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| 字段 | 值 |
| --- | --- |
| SQLSTATE | `02000` |
| 条件名 | `no_data` |
| 状态 | `有效` |
| 已知存在于 | `7.4` |
| 锁定快照 | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| 宏 | `ERRCODE_NO_DATA` |
| 别名 | `—` |

<!-- source facts: data/errcodes/02000.json -->
<!-- END SQLSTATE FACTS -->

## 含义 {#meaning}

确认的 18.6 实现位于 `contrib/amcheck/verify_nbtree.c`，索引一致性诊断在 `DEBUG1` 或 `DEBUG2` 使用 `ERRCODE_NO_DATA`。这是内部诊断用途，不是普通 `SELECT` 无行语义。本证据具体展开三个代表性组；源码中的其他路径不在这组选定消息内。

## 消息与诊断 {#messages}

本次选定的固定消息组为：

- `DEBUG1`、内部 `errmsg_internal`：`harmless fast root mismatch in index "%s"`，内部 detail 为 `Fast root block %u (level %u) differs from true root block %u (level %u).`。源码明确把它标为 harmless。
- `DEBUG1`、内部 `errmsg_internal`：`block %u of index "%s" concurrently deleted`。这个分支的确认组没有 detail 或 hint。
- `DEBUG1`、普通 `errmsg`/`errdetail`/`errhint`：`index uniqueness can not be checked for index tid=(%u,%u) in index "%s"`，detail 为 `It doesn't have visible heap tids and key is equal to the tid=(%u,%u)%s (points to heap tid=(%u,%u)).`，hint 为 `VACUUM the table and repeat the check.`。VACUUM hint 只属于这个组。

## 诊断 {#diagnosis}

若代码来自 amcheck，记录检查、索引、block/TID 上下文和服务器日志严重级别。fast-root mismatch 已被源码标为 harmless，应结合上下文记录，不要自动当作损坏修复。对于并发删除，应关联并发操作或快照，待相关活动稳定后再决定是否重跑。对于 uniqueness-uncheckable 组，应检查指定索引，并只在该组给出提示时执行 VACUUM 后重跑。应用无行处理应检查实际命令结果或过程条件；PL/pgSQL 的 `NO_DATA_FOUND` 是 `P0002`，不是 `02000` 的通用同义词。

## 处理 {#response}

按分支处理：不要把 harmless fast-root 诊断自动变成修复；并发删除要调查并发状态；只有 uniqueness-uncheckable 组给出该提示时，才先执行 `VACUUM` 再重跑。不要要求每个 `DEBUG` 发现都做维护，也不要仅因 SQLSTATE 属于 02 类就给普通 `SELECT` 加无行异常或重试。

## 版本 {#versions}

`02000` 在锁定目录 9.0.23 至 18.6 以及 19 Beta 3 中存在，`known_present_by` 为 7.4。18.6 证据覆盖 amcheck DEBUG 路径；其他来源需要独立源码证据。

## 相关 {#related}

[`P0002`](../p0002/) 是 PL/pgSQL `no_data_found`；[`02001`](../02001/) 涉及额外动态结果集；[`00000`](../00000/) 是成功完成。

## 来源 {#sources}

- [`errcodes.txt`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L96) — 定义，SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba`.
- [`verify_nbtree.c`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/contrib/amcheck/verify_nbtree.c#L992-L1001) — 固定路径，SHA-256 `a59ae7540a990e5a70e8eb9cedbcad7c62e3e86b1ad426142c8931ee188b752d`。
- [结构化证据](../../data/evidence/02000.json) — 固定来源、消息和运行边界。
