Re: Summary table trigger example race condition

From: Mark Kirkwood <markir(at)paradise(dot)net(dot)nz>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Summary table trigger example race condition
Date: 2006-01-06 01:00:34
Message-ID: 43BDC132.90007@paradise.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-patches

Jim C. Nasby wrote:
> http://www.postgresql.org/docs/current/static/plpgsql-trigger.html
> example 36-4 has a race condition in the code that checks to see if a
> row exists. It should use the code from example 36-1. This patch fixes
> that. It also adds some commands to show what the summary table output
> looks like. Unfortunately gamke html is bombing with some kind of
> library error, so I can't verify that I didn't break the sgml.
>
> BTW, should this have gone to -docs instead?

Your SGML builds fine for me.

However, I think the actual change is not quite right - after running
the INSERT, DELETE, UPDATE sequence at the end I see:

ware=# SELECT * FROM sales_summary_bytime;
time_key | amount_sold | units_sold | amount_cost
----------+-------------+------------+-------------
1 | 30.00 | 13 | 50.00
2 | 90.00 | 47 | 283.00
(2 rows)

ware=# select * from sales_fact;
time_key | product_key | store_key | amount_sold | units_sold |
amount_cost
----------+-------------+-----------+-------------+------------+-------------
1 | 2 | 1 | 20.00 | 10 |
35.00
2 | 2 | 1 | 40.00 | 30 |
135.00
2 | 3 | 1 | 10.00 | 2 |
13.00
(3 rows)

i.e - sales_summary_bytime and sales_fact do not agree with each other
any more! I suspect that the loop does the update even if the insert is
successful (so double counts).

BTW - Nice to see someone reading this... :-)

Best wishes

Mark

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Jim C. Nasby 2006-01-06 03:04:15 Re: [PATCHES] Summary table trigger example race condition
Previous Message Jim C. Nasby 2006-01-05 21:36:45 Summary table trigger example race condition

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2006-01-06 01:01:23 Re: [HACKERS] Inconsistent syntax in GRANT
Previous Message Jim C. Nasby 2006-01-05 21:36:45 Summary table trigger example race condition