Issue Details (XML | Word | Printable)

Key: CORE-2633
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Vlad Khorsun
Reporter: prenosil
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Firebird Core

SELECT WITH LOCK with no fields are accessed clears the data

Created: 17/Sep/09 12:33 AM   Updated: 17/Sep/09 06:37 PM
Return to search
Component/s: Engine
Affects Version/s: 2.5 Alpha 1, 2.5 Beta 1, 2.5 Beta 2
Fix Version/s: 2.5 RC1

Time Tracking:
Not Specified

Environment: WinXP

Planning Status: Unspecified


 Description  « Hide
"SELECT ... WITH LOCK" inside Execute Block corrupts data, even subsequent ROLLBACK does not help.
In the following script, the first select will show

SELECT * FROM T;
A B
==================== ===========
aaaa 1
bbbb 2
cccc 3

while the subsequent selects (before and after Rollback) will show
SELECT * FROM T;
A B
==================== ===========
                               0
                               0
                               0


--------------------
CREATE DATABASE 'C:\TESTDB.FDB';
CREATE TABLE T (A VARCHAR(20), B INTEGER);
INSERT INTO T(A,B) VALUES('aaaa',1);
INSERT INTO T(A,B) VALUES('bbbb',2);
INSERT INTO T(A,B) VALUES('cccc',3);
COMMIT;

SELECT * FROM T;

SET TERM ^;
EXECUTE BLOCK AS
DECLARE I INTEGER;
BEGIN
  FOR SELECT 1 FROM T WITH LOCK INTO :I DO I=I;
END^
SET TERM ;^

SELECT * FROM T;

ROLLBACK;

SELECT * FROM T;

DROP DATABASE;
--------------------

 All   Comments   Work Log   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Sean Leyne added a comment - 17/Sep/09 05:29 AM - edited
Edited the case summary/title to provide clearer details for possible readers

Vlad Khorsun added a comment - 17/Sep/09 06:30 PM
The bug is related to the feature CORE-1598 (Optimize data retrieval for tables when no fields are accessed).
If no fields ia accessed engine not creates record in memory. If NO LOCK also specified engine must create
dummy update and (as there is no record in memory) writes empty backversion on disk. ROLLBACK have no
effect as restored backversion have all fields set to empty values.

I see two ways to fix it :
a) disable feature if NO LOCK is used, or
b) re-fetch the record in VIO_writelock if there is no record in memory

I think (a) is better and will commit it.

Vlad Khorsun added a comment - 17/Sep/09 06:34 PM
More exact description