home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!ucbvax!mtxinu!sybase!houdini!jeffl
- From: jeffl@houdini.sybase.com (Jeff Lichtman)
- Newsgroups: comp.databases.theory
- Subject: Re: What is the _Halloween Problem_ ?
- Message-ID: <22838@sybase.sybase.com>
- Date: 26 Aug 92 20:01:00 GMT
- References: <1992Aug24.000720.7563@news2.cis.umn.edu>
- Sender: news@Sybase.COM
- Organization: Committee to Increase The Entropy
- Lines: 74
-
- In article <1992Aug24.000720.7563@news2.cis.umn.edu>, kencham@ulysses.cs.umn.edu (Deepak) writes:
- > What is the _Halloween Problem_ ?
-
- The Halloween Problem is that, when applying updates to a table, the results
- of the updates might depend on the order that they are applied. For example,
- suppose you have the following table:
-
- employees (id, salary, manager_id)
-
- and you want to give a 10% raise to everyone who earns less than his or her
- manager. In SQL, you would write the query like this:
-
- update employees
- set salary = salary * 1.10
- where salary <
- (select salary
- from employees e
- where e.id = employees.manager_id)
-
- (This is how you might write it in Sybase's version of SQL, anyway.)
-
- Now suppose the data looked like this:
-
- id salary manager_id
-
- 1 1000.00 NULL
- 2 950.00 1
- 3 950.00 1
- 4 960.00 2
- 5 960.00 3
-
- Let's say the database engine updated the rows one at a time, as it saw
- them. If it started from the first row and worked its way down, it would
- get the following result:
-
- id salary manager_id
-
- 1 1000.00 NULL
- 2 1045.00 1
- 3 1045.00 1
- 4 1056.00 2
- 5 1056.00 3
-
- But, if it started at the last row and worked its way up, it would get the
- following result:
-
- id salary manager_id
-
- 1 1000.00 NULL
- 2 1045.00 1
- 3 1045.00 1
- 4 960.00 2
- 5 960.00 3
-
- In the latter case, employees 4 and 5 don't get the raise because they are
- earning more than their managers at the time when the database engine looks
- at their rows.
-
- Relational theory mandates that the updates be determined by the state of
- the data when the update started. That is, an update is not allowed to make
- any decisions or calculations based on its own partial results.
-
- Most relational database systems solve this problem by logging all the changes
- that the update will produce before they make any of the changes. Only
- after all the changes are logged will they be applied. This effectively
- makes the results of an update depend on the state of the data at the time
- the update started.
-
- By the way, I have it on good authority, that it's called the "Halloween
- Problem" because it was first thought of on Halloween.
- ---
- Jeff Lichtman at Sybase
- {mtxinu,pacbell}!sybase!jeffl -or- jeffl@sybase.com
- "Saints should always be judged guilty until they are proved innocent..."
-