Discuz!小编 发表于 2026-8-15 18:19:36

出现孤儿贴,帖子列表有标题,点进去提示:

没有找到帖子


[ 点击这里返回上一页 ]


AI分析:


用户「辣椒炒肉」(uid=38) 在 fid=2 发帖 → Discuz 标准流程 forum.php → post/newthread → model_thread->insertpost → table_forum_post->insert_post → _insert_use_db → DB::insert → 给首帖分配了 pid=276,但 276 已经被占用,INSERT forum_post 触发 Duplicate 失败 → 而 forum_thread(tid=162) 在这之前已经插进去了、MyISAM 无事务回滚 → 孤儿主题。


结论:



[*] X5.0.2 自身的 pid 分配机制问题——forum_post.pid 非自增,由应用层分配,分配逻辑分到了一个已存在的 pid。
[*]这解释了"偶发":只有当分配逻辑分到已占用 pid 时才触发,平时多数时候分配的 pid 是空的就能成功。也解释了你说的"有人发帖时才出现"——发帖动作本身触发分配,撞了就孤儿。


我知道答案 回答被采纳将会获得1 贡献 已有9人回答

杰克 发表于 2026-8-15 18:20:01

别听 AI 瞎指导
       

.ce-block {    margin-bottom: 20px;}.ce-block__content,.ce-toolbar__content {        /* max-width:calc(100% - 50px) */        margin-left: auto;    margin-right: auto;}.ce-paragraph {    line-height: 1.6em;    outline: none;    text-indent: 2em;    font-size: 16px;}.ce-paragraph--right {    text-align: right;}.ce-paragraph--center {    text-align: center;}.ce-paragraph--left {    text-align: left;}.ce-paragraph--justify {    text-align: justify;}.ce-paragraph-text-indent {    text-align: justify;}.ce-paragraph:empty::before{content: attr(data-placeholder);color: #707684;font-weight: normal;opacity: 0;}/** Show placeholder at the first paragraph if Editor is empty */.codex-editor--empty .ce-block:first-child .ce-paragraph:empty::before {opacity: 1;}.codex-editor--toolbox-opened .ce-block:first-child .ce-paragraph:empty::before,.codex-editor--empty .ce-block:first-child .ce-paragraph:empty:focus::before {opacity: 0;}.ce-paragraph p:first-of-type{    margin-top: 0;}.ce-paragraph p:last-of-type{    margin-bottom: 0;}.svg-icon {    width: 1em;    height: 1em;}.svg-icon path,.svg-icon polygon,.svg-icon rect {    fill: #4691f6;}.svg-icon circle {    stroke: #4691f6;    stroke-width: 1;}.inline-code {background: rgba(250, 239, 240, 0.78);color: #b44437;padding: 3px 4px;border-radius: 5px;margin: 0 1px;font-family: inherit;font-size: 0.86em;font-weight: 500;letter-spacing: 0.3px;}

KarlMock59 发表于 2026-8-15 18:20:34

皇上,AI在耍你啊

海军大都督 发表于 2026-8-15 18:21:18

哈哈。那是啥问题啊?

Sylvia 发表于 2026-8-15 18:22:17

那咋整啊?

KarlMock59 发表于 2026-8-15 18:23:07

monkeye 发表于 2026-8-4 21:14
别听 AI 瞎指导;                        来来,看看AI给的解决方案:
       

                        根因彻底定位

       

                        insertpost() 第 884 行:
       

                        php$pid = table_forum_post_tableid::t()->insert(['pid' => null], true);
       

                        pid 靠 pre_forum_post_tableid 表的 pid 列自增分配(插一行 null,拿回自增 id)。问题就是:这个表的 AUTO_INCREMENT 计数器落后了——它还停在 276 附近,但 forum_post 里 pid 早就用到 279 了。所以它分出一个早已被占用的 276 → INSERT forum_post 撞 Duplicate → thread 已先插、无事务 → 孤儿。
       

                        计数器落后,大概率是历史备份恢复或迁移时 forum_post_tableid 表状态和 forum_post 不一致造成的(计数器是旧的,pid 已增长)。
       

                        治本操作(宝塔 phpMyAdmin 执行)

       

                        第 1 步——确认计数器落后:
       

                        sqlSHOW TABLE STATUS LIKE 'pre_forum_post_tableid';SELECT MAX(pid) FROM pre_forum_post;
       

                        看第一个结果里的 Auto_increment 列,对比第二个的 MAX(pid)(应该是 279)。如果 Auto_increment ≤ 279,确诊。
       

                        第 2 步——把计数器推到全新区间:
       

                        sqlALTER TABLE pre_forum_post_tableid AUTO_INCREMENT = 280;
       

                        (280 = MAX(pid) + 1;如果第 1 步查出来 MAX(pid) 不是 279,就改成那个值 +1)
       

                        第 3 步——验证:发个测试帖,能正常打开就成。
       

.ce-block {    margin-bottom: 20px;}.ce-block__content,.ce-toolbar__content {        /* max-width:calc(100% - 50px) */        margin-left: auto;    margin-right: auto;}.ce-paragraph {    line-height: 1.6em;    outline: none;    text-indent: 2em;    font-size: 16px;}.ce-paragraph--right {    text-align: right;}.ce-paragraph--center {    text-align: center;}.ce-paragraph--left {    text-align: left;}.ce-paragraph--justify {    text-align: justify;}.ce-paragraph-text-indent {    text-align: justify;}.ce-paragraph:empty::before{content: attr(data-placeholder);color: #707684;font-weight: normal;opacity: 0;}/** Show placeholder at the first paragraph if Editor is empty */.codex-editor--empty .ce-block:first-child .ce-paragraph:empty::before {opacity: 1;}.codex-editor--toolbox-opened .ce-block:first-child .ce-paragraph:empty::before,.codex-editor--empty .ce-block:first-child .ce-paragraph:empty:focus::before {opacity: 0;}.ce-paragraph p:first-of-type{    margin-top: 0;}.ce-paragraph p:last-of-type{    margin-bottom: 0;}.svg-icon {    width: 1em;    height: 1em;}.svg-icon path,.svg-icon polygon,.svg-icon rect {    fill: #4691f6;}.svg-icon circle {    stroke: #4691f6;    stroke-width: 1;}.ce-block {        margin-top: 20px;    margin-bottom: 20px;}.ce-block__content,.ce-toolbar__content {        /* max-width:calc(100% - 50px) */        margin-left: auto;    margin-right: auto;}/** * Plugin styles */.ce-header {position: relative;padding: 1px 0px 1px 15px;margin: 0;line-height: 1.25em;outline: none;margin-bottom: 10px;}.ce-header p,.ce-header div {padding: 0 !important;margin: 0 !important;}.ce-header::before {    content: "";    width: 0;    height: 0;    border-top: 8px solid transparent;    border-bottom: 8px solid transparent;    border-left: 12px solid #155BD5;    position: absolute;    left: 0;    top: 50%;    transform: translateY(-50%);    background-color: transparent;    border-radius: 0;}/** * Styles for Plugin icon in Toolbar */.ce-header__icon {}.ce-header::before {position: absolute;content: attr(data-placeholder);color: #707684;font-weight: normal;display: none;cursor: text;}.ce-header:empty::before {display: block;}.ce-header:empty:focus::before {display: none;}/* FontSize */h1.ce-header {    font-size: 2.0em;}h2.ce-header {    font-size: 1.7em;}h3.ce-header {    font-size: 1.4em;}h4.ce-header {    font-size: 1.15em;}h5.ce-header {    font-size: 0.95em;}h6.ce-header {    font-size: 0.8em;}/* Alignment*/.ce-header--right {text-align: right;}.ce-header--center {text-align: center;}.ce-header--left {text-align: left;}.ce-header--justify {text-align: justify;}.inline-code {background: rgba(250, 239, 240, 0.78);color: #b44437;padding: 3px 4px;border-radius: 5px;margin: 0 1px;font-family: inherit;font-size: 0.86em;font-weight: 500;letter-spacing: 0.3px;}

KarlMock59 发表于 2026-8-15 18:23:48

AI只能处理简单的问题,复杂的问题能让网站崩掉

杰克 发表于 2026-8-15 18:24:33

首先你描述的问题就不够 清楚,这种现象是需要 具体排查 的,可能性很多

瑾瑜 发表于 2026-8-15 18:25:02

这个词都是你自己新造的
       

.ce-block {    margin-bottom: 20px;}.ce-block__content,.ce-toolbar__content {        /* max-width:calc(100% - 50px) */        margin-left: auto;    margin-right: auto;}.ce-paragraph {    line-height: 1.6em;    outline: none;    text-indent: 2em;    font-size: 16px;}.ce-paragraph--right {    text-align: right;}.ce-paragraph--center {    text-align: center;}.ce-paragraph--left {    text-align: left;}.ce-paragraph--justify {    text-align: justify;}.ce-paragraph-text-indent {    text-align: justify;}.ce-paragraph:empty::before{content: attr(data-placeholder);color: #707684;font-weight: normal;opacity: 0;}/** Show placeholder at the first paragraph if Editor is empty */.codex-editor--empty .ce-block:first-child .ce-paragraph:empty::before {opacity: 1;}.codex-editor--toolbox-opened .ce-block:first-child .ce-paragraph:empty::before,.codex-editor--empty .ce-block:first-child .ce-paragraph:empty:focus::before {opacity: 0;}.ce-paragraph p:first-of-type{    margin-top: 0;}.ce-paragraph p:last-of-type{    margin-bottom: 0;}.svg-icon {    width: 1em;    height: 1em;}.svg-icon path,.svg-icon polygon,.svg-icon rect {    fill: #4691f6;}.svg-icon circle {    stroke: #4691f6;    stroke-width: 1;}.inline-code {background: rgba(250, 239, 240, 0.78);color: #b44437;padding: 3px 4px;border-radius: 5px;margin: 0 1px;font-family: inherit;font-size: 0.86em;font-weight: 500;letter-spacing: 0.3px;}

凡若尘 发表于 2026-8-15 18:25:21

建议提问步骤:

我在执行了发帖操作之后,页面提示:

没有找到帖子(如图)

此时地址栏显示的URL是:******************

…………
页: [1]
查看完整版本: 出现孤儿贴,帖子列表有标题,点进去提示: