mikeizbicki / cmc-csci143

big data course materials
40 stars 76 forks source link

Quiz Notes (Transactions and Locks Questions) #478

Closed abizermamnoon closed 7 months ago

abizermamnoon commented 8 months ago

Hi Mike,

In Problem 55, after line 7, I executed this command to find row level locks:

SELECT *
FROM t, pgrowlocks('t') AS p
WHERE p.locked_row = t.ctid;
 a | locked_row | locker | multi | xids  |       modes       | pids
---+------------+--------+-------+-------+-------------------+------
 9 | (0,2)      |    706 | f     | {706} | {"For Key Share"} | {47}
(1 row)

Is this row level lock generated by table u somehow?

In Problem 64, on line 10, my hypothesis was that an error would be thrown because u = 8 is not in table t. However, it got blocked. Why did it get blocked?

mikeizbicki commented 7 months ago

Problem 55: table u has a FOREIGN KEY constraint on table t. That means that whenever you INSERT INTO u, you need to run a corresponding SELECT statement on t in order to figure out if the INSERT violates the constraint. This "hidden" SELECT is generating this For Key Share lock.

Problem 64: