pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedIs the Halloween problem an issue in Postgres
7+ messages / 6 participants
[nested] [flat]
* Is the Halloween problem an issue in Postgres
@ 2020-12-02 20:27 guyren@icloud.com
2020-12-02 20:48 ` Re: Is the Halloween problem an issue in Postgres Tom Lane <tgl@sss.pgh.pa.us>
2020-12-02 22:02 ` Re: Is the Halloween problem an issue in Postgres Thomas Kellerer <shammat@gmx.net>
0 siblings, 2 replies; 7+ messages in thread
From: guyren@icloud.com @ 2020-12-02 20:27 UTC (permalink / raw)
To: pgsql-general
The Halloween problem is that it is a challenge for the database if you’re updating a field that is also in the WHERE clause of the same query.
I just saw a presentation from someone about how in SQL Server he recommended writing changes to a temp table and then writing them to the table as being much more efficient.
Does Postgres handle this problem efficiently, or should we follow a similar strategy?
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
@ 2020-12-02 20:48 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 7+ messages in thread
From: Tom Lane @ 2020-12-02 20:48 UTC (permalink / raw)
To: guyren@icloud.com; +Cc: pgsql-general
guyren@icloud.com writes:
> The Halloween problem is that it is a challenge for the database if you’re updating a field that is also in the WHERE clause of the same query.
> I just saw a presentation from someone about how in SQL Server he recommended writing changes to a temp table and then writing them to the table as being much more efficient.
That's nonsense as far as Postgres is concerned.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
@ 2020-12-02 22:02 ` Thomas Kellerer <shammat@gmx.net>
2020-12-02 22:08 ` Re: Is the Halloween problem an issue in Postgres Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-02 22:11 ` Re: Is the Halloween problem an issue in Postgres raf <raf@raf.org>
1 sibling, 2 replies; 7+ messages in thread
From: Thomas Kellerer @ 2020-12-02 22:02 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
guyren@icloud.com schrieb am 02.12.2020 um 21:27:
> The Halloween problem is that it is a challenge for the database if
> you’re updating a field that is also in the WHERE clause of the same
> query.
>
> I just saw a presentation from someone about how in SQL Server he
> recommended writing changes to a temp table and then writing them to
> the table as being much more efficient.
It sounds strange to me, that this _is_ actually a problem.
Why exactly is that a problem in SQL Server?
And what are the consequences if you do it nevertheless.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
2020-12-02 22:02 ` Re: Is the Halloween problem an issue in Postgres Thomas Kellerer <shammat@gmx.net>
@ 2020-12-02 22:08 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-02 22:23 ` Re: Is the Halloween problem an issue in Postgres raf <raf@raf.org>
1 sibling, 1 reply; 7+ messages in thread
From: Adrian Klaver @ 2020-12-02 22:08 UTC (permalink / raw)
To: Thomas Kellerer <shammat@gmx.net>; pgsql-general@lists.postgresql.org
On 12/2/20 2:02 PM, Thomas Kellerer wrote:
> guyren@icloud.com schrieb am 02.12.2020 um 21:27:
>> The Halloween problem is that it is a challenge for the database if
>> you’re updating a field that is also in the WHERE clause of the same
>> query.
>>
>> I just saw a presentation from someone about how in SQL Server he
>> recommended writing changes to a temp table and then writing them to
>> the table as being much more efficient.
>
> It sounds strange to me, that this _is_ actually a problem.
>
> Why exactly is that a problem in SQL Server?
Yeah that was a new one to me. A quick search found:
https://www.sqlshack.com/the-halloween-problem-in-sql-server-and-suggested-solutions/
> And what are the consequences if you do it nevertheless.
>
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
2020-12-02 22:02 ` Re: Is the Halloween problem an issue in Postgres Thomas Kellerer <shammat@gmx.net>
2020-12-02 22:08 ` Re: Is the Halloween problem an issue in Postgres Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-12-02 22:23 ` raf <raf@raf.org>
2020-12-02 22:35 ` Re: Is the Halloween problem an issue in Postgres Ron <ronljohnsonjr@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: raf @ 2020-12-02 22:23 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On Wed, Dec 02, 2020 at 02:08:41PM -0800, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> On 12/2/20 2:02 PM, Thomas Kellerer wrote:
> > guyren@icloud.com schrieb am 02.12.2020 um 21:27:
> > > The Halloween problem is that it is a challenge for the database if
> > > you’re updating a field that is also in the WHERE clause of the same
> > > query.
> > >
> > > I just saw a presentation from someone about how in SQL Server he
> > > recommended writing changes to a temp table and then writing them to
> > > the table as being much more efficient.
> >
> > It sounds strange to me, that this _is_ actually a problem.
> >
> > Why exactly is that a problem in SQL Server?
>
> Yeah that was a new one to me. A quick search found:
>
> https://www.sqlshack.com/the-halloween-problem-in-sql-server-and-suggested-solutions/
>
> > And what are the consequences if you do it nevertheless.
It looks like the anser is no (unless I've misunderstood the problem):
create table a (id serial not null primary key, a integer not null, b integer not null);
create index a_a on a(a);
insert into a (a, b) values (1, 2);
insert into a (a, b) values (2, 3);
insert into a (a, b) values (3, 4);
insert into a (a, b) values (4, 5);
insert into a (a, b) values (5, 6);
insert into a (a, b) values (6, 7);
update a set a = a + 1 where a < 4;
select * from a order by id;
drop table a cascade;
results in:
id | a | b
----+---+---
1 | 2 | 2
2 | 3 | 3
3 | 4 | 4
4 | 4 | 5
5 | 5 | 6
6 | 6 | 7
It's the same with or without the index on a(a).
cheers,
raf
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
2020-12-02 22:02 ` Re: Is the Halloween problem an issue in Postgres Thomas Kellerer <shammat@gmx.net>
2020-12-02 22:08 ` Re: Is the Halloween problem an issue in Postgres Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-02 22:23 ` Re: Is the Halloween problem an issue in Postgres raf <raf@raf.org>
@ 2020-12-02 22:35 ` Ron <ronljohnsonjr@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Ron @ 2020-12-02 22:35 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 12/2/20 4:23 PM, raf wrote:
> On Wed, Dec 02, 2020 at 02:08:41PM -0800, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
>> On 12/2/20 2:02 PM, Thomas Kellerer wrote:
>>> guyren@icloud.com schrieb am 02.12.2020 um 21:27:
>>>> The Halloween problem is that it is a challenge for the database if
>>>> you’re updating a field that is also in the WHERE clause of the same
>>>> query.
>>>>
>>>> I just saw a presentation from someone about how in SQL Server he
>>>> recommended writing changes to a temp table and then writing them to
>>>> the table as being much more efficient.
>>> It sounds strange to me, that this _is_ actually a problem.
>>>
>>> Why exactly is that a problem in SQL Server?
>> Yeah that was a new one to me. A quick search found:
>>
>> https://www.sqlshack.com/the-halloween-problem-in-sql-server-and-suggested-solutions/
>>
>>> And what are the consequences if you do it nevertheless.
> It looks like the anser is no (unless I've misunderstood the problem):
>
> create table a (id serial not null primary key, a integer not null, b integer not null);
> create index a_a on a(a);
> insert into a (a, b) values (1, 2);
> insert into a (a, b) values (2, 3);
> insert into a (a, b) values (3, 4);
> insert into a (a, b) values (4, 5);
> insert into a (a, b) values (5, 6);
> insert into a (a, b) values (6, 7);
> update a set a = a + 1 where a < 4;
> select * from a order by id;
> drop table a cascade;
>
> results in:
>
> id | a | b
> ----+---+---
> 1 | 2 | 2
> 2 | 3 | 3
> 3 | 4 | 4
> 4 | 4 | 5
> 5 | 5 | 6
> 6 | 6 | 7
>
> It's the same with or without the index on a(a).
The Halloween Problem does not seem to cause the statement to fail, but to
run slowly.
--
Angular momentum makes the world go 'round.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Is the Halloween problem an issue in Postgres
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
2020-12-02 22:02 ` Re: Is the Halloween problem an issue in Postgres Thomas Kellerer <shammat@gmx.net>
@ 2020-12-02 22:11 ` raf <raf@raf.org>
1 sibling, 0 replies; 7+ messages in thread
From: raf @ 2020-12-02 22:11 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On Wed, Dec 02, 2020 at 11:02:07PM +0100, Thomas Kellerer <shammat@gmx.net> wrote:
> guyren@icloud.com schrieb am 02.12.2020 um 21:27:
> > The Halloween problem is that it is a challenge for the database if
> > you’re updating a field that is also in the WHERE clause of the same
> > query.
> >
> > I just saw a presentation from someone about how in SQL Server he
> > recommended writing changes to a temp table and then writing them to
> > the table as being much more efficient.
>
> It sounds strange to me, that this _is_ actually a problem.
>
> Why exactly is that a problem in SQL Server?
> And what are the consequences if you do it nevertheless.
According to wikipedia, this problem was discovered on
Halloween day, 1976. I find it hard to believe that any
database would still exhibit that behaviour 44 years
later.
cheers,
raf
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2020-12-02 22:35 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 20:27 Is the Halloween problem an issue in Postgres guyren@icloud.com
2020-12-02 20:48 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-12-02 22:02 ` Thomas Kellerer <shammat@gmx.net>
2020-12-02 22:08 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-12-02 22:23 ` raf <raf@raf.org>
2020-12-02 22:35 ` Ron <ronljohnsonjr@gmail.com>
2020-12-02 22:11 ` raf <raf@raf.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox