PostgreSQL 中存在万圣节问题吗?

万圣节问题(Halloween Problem)是数据库系统中的一个现象,它指的是当一个查询检索了一组行,然后修改了其中一行或多行,修改后的行再次满足查询的条件,进而导致在相同的更新操作中再次访问该行。在某些情况下甚至可能导致无限循环。 这个问题最初是由 Don Chamberlin、Pat Selinger 和 Morton Astrahan 在 1976 年的万圣节那天发现,当时他们正在处理的一个查询本应给那些收入低于 25,000 美元的员工加薪 10%,但执行完成后,数据库中所有员工的收入都至少达到了 25,000 美元。这是由于更新过的记录也对查询执行引擎可见,并且继续符合查询条件,记录多次匹配,每次匹配都被加薪 10%,直到它们都超过 25,000 美元。 Halloween Problem 这个名字并没有描述问题的性质,仅仅是因为它被发现的那天恰好是万圣节🎃。 Pat and Morton discovered this problem on Halloween… I remember they came into my office and said, “Chamberlin, look at this. We have to make sure that when the optimizer is making a plan for processing an update, it doesn’t use an index that is based on the field that is being updated....

July 6, 2024 · 4 min · 775 words · pg-x