فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة SQL
أمثلة قصيرة وبسيطة
الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.
المثال ١: wait-for graph كجدول
Sample output (press Run to produce your own): t_a | t_b ----+---- T1 | T2 (1 row)
المثال ٢: مفيش deadlock
Sample output (press Run to produce your own): two_cycles ---------- 0 (1 row)
المثال ٣: الـ timestamp والعملية المتأخرة
Sample output (press Run to produce your own): decision ------------------- abort and restart T (1 row)
اختبار قصير
اختبر فهمك
1. A deadlock is:
2. The DBMS usually resolves a deadlock by:
3. Locking in a fixed order:
4. Timestamp ordering uses:
5. Which level allows dirty reads?
تمارين برمجة
جرّب بإيدك
التمرين 1
جدول waits فيه (T1,T2) و(T2,T3) و(T3,T1). اعرض كل الصفوف. هل فيه cycle؟ فكّر قبل ما تقرا النتيجة.
The waits table holds (T1,T2), (T2,T3), (T3,T1). Show all rows. Is there a cycle? Think before reading the result.
(output appears here)
sql('''
CREATE TABLE waits (waiter TEXT, holder TEXT);
INSERT INTO waits VALUES ('T1','T2'), ('T2','T3'), ('T3','T1');
SELECT * FROM waits ORDER BY waiter;
''')
Output
waiter | holder -------+------- T1 | T2 T2 | T3 T3 | T1 (3 rows)
التمرين 2
اختار ضحية: الـ transaction اللي معاها أقل عدد writes من جدول tx(name, writes).
Pick a victim: the transaction with the fewest writes from tx(name, writes).
(output appears here)
sql('''
CREATE TABLE tx (name TEXT, writes INTEGER);
INSERT INTO tx VALUES ('T1', 5), ('T2', 2), ('T3', 9);
SELECT name AS victim FROM tx ORDER BY writes LIMIT 1;
''')
Output
victim ------ T2 (1 row)
مشروع صغير في آخر المحاضرة
اكتشف deadlock واختار الضحية
الداتا: Wait-for data: 4 waits between 3 transactions. Written for this course (our own data, free to reuse).
License / source: Our own sample data; SQLite is in the public domain. Dataset page
الخطوات
- جدولين: waits وـ tx(name, writes).
- اكتشف أزواج الانتظار المتبادل (T_a تستنى T_b وT_b تستنى T_a). المتوقع: T1 وT2.
- اختار الضحية من الاتنين بأقل writes. المتوقع: T2.
- اعرض الضحية.
Expected output (press Run to produce your own): t_a | t_b ----+---- T1 | T2 (1 row) victim ------ T2 (1 row)
مشروع نهاية الفصل
ملف المشروع العملي للفصل 10
ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.
Credits: the topic order follows the lecture list of the course TDDD12 Database Technology at Linköping University (https://www.ida.liu.se/~TDDD12/fo/), whose reading guide is based on the textbook Fundamentals of Database Systems by Elmasri and Navathe. We found no reuse licence on that page, so we link to it and copy nothing from it: the explanations, diagrams, data and code in this lecture are our own. Reference: Elmasri and Navathe, Fundamentals of Database Systems, the chapters on concurrency control.