Course / دورة
Databases under loadقواعد البيانات تحت الحِمل
Correct when two people write at once, and quick when the table is large
صحيحة حين يكتب اثنان معًا، وسريعة حين يكبر الجدول
advanced 16 lessons 4 chapters 14 hours
Before you start / قبل أن تبدأ: Software engineering foundations
0 / 16 lessons completed / دروس مكتملة
What you will be able to do / ماذا ستستطيع أن تفعل
- Make the database refuse bad data, instead of hoping every writer remembers تجعل قاعدة البيانات ترفض البيانات السيئة، بدل أن تأمل أن يتذكر كل كاتب
- Say why a query is slow, and whether an index would help تقول لماذا الاستعلام بطيء، وهل ينفع الفهرس
- Keep two people writing the same row from losing each other's work تمنع كاتبَين على الصف نفسه من إضاعة عمل أحدهما الآخر
- Keep a table usable after it has grown past what fits in your head تُبقي جدولًا صالحًا بعد أن ينمو فوق ما يسع رأسك
1 Guarantees the database can makeضمانات تستطيع قاعدة البيانات تقديمها 4
-
1
Let the database say no / دع قاعدة البيانات تقول لا
Every rule you enforce only in application code is a rule that holds until somebody writes from somewhere else. A constraint is the same rule stated where nothing can go around it.
كل قاعدة تفرضها في كود التطبيق وحده قاعدةٌ تصمد حتى يكتب أحدهم من موضع آخر. والقيد هو القاعدة نفسها مذكورةً حيث لا يستطيع شيء الالتفاف حولها.
-
2
A type is the first constraint / النوع هو القيد الأول
Choosing a column type looks like a storage decision and is really a decision about what the column is allowed to mean. Most of the damage comes from three choices, and all three are made in the first ten minutes of a table's life.
اختيار نوع العمود يبدو قرار تخزين وهو في الحقيقة قرار عمّا يُسمح للعمود أن يعنيه. ومعظم الضرر يأتي من ثلاثة اختيارات، وتُتخذ الثلاثة في أول عشر دقائق من عمر الجدول.
-
3
A key has one job, and meaning is not it / للمفتاح عمل واحد، وليس المعنى منه
A primary key identifies a row for as long as the row exists. Anything with meaning can change, and a key that changes takes every row pointing at it along with it — which is why the best keys say nothing at all.
المفتاح الأساسي يعرّف صفًّا ما دام الصف موجودًا. وكل ما له معنى يمكن أن يتغير، والمفتاح الذي يتغير يأخذ معه كل صف يشير إليه — ولهذا فأفضل المفاتيح ما لا يقول شيئًا البتة.
-
4
Deleting, without losing what mattered / الحذف، دون ضياع ما كان مهمًّا
DELETE is honest and often wrong: a cancelled booking still happened, and a departed guest was still paid by. The usual answer is a flag instead of a delete — which is right, and quietly breaks two things nobody warns you about.
DELETE صادقة وخاطئة غالبًا: فالحجز الملغى قد وقع فعلًا، والنزيل الراحل قد دفع فعلًا. والجواب المعتاد رايةٌ بدل الحذف — وهو صواب، ويكسر بهدوء شيئين لا يحذّرك منهما أحد.
2 Why a query is slowلماذا الاستعلام بطيء 4
-
5
The database is reading every row / قاعدة البيانات تقرأ كل صف
A query with no index behind it answers by looking at everything. That is invisible at a thousand rows and fatal at a million, and the change happens without a line of code being touched.
الاستعلام الذي لا فهرس خلفه يجيب بالنظر إلى كل شيء. وذلك غير مرئي عند ألف صف وقاتل عند مليون، ويقع التحول دون مسّ سطر كود واحد.
-
6
What an index actually is / ما الفهرس فعلًا
An index is a second copy of one or two columns, kept in order, with a pointer back to the row. Everything an index can and cannot do follows from the words "kept in order", and reasoning from those three words gets you further than memorising rules.
الفهرس نسخة ثانية من عمود أو عمودين، محفوظة مرتّبة، ومعها مؤشر إلى الصف. وكل ما يستطيعه الفهرس وما لا يستطيعه يتبع كلمتَي «محفوظة مرتّبة»، والاستدلال من تلك الكلمات يبلغ بك أبعد من حفظ القواعد.
-
7
Ask the database what it is going to do / اسأل قاعدة البيانات ماذا ستفعل
You do not have to guess whether an index is being used. EXPLAIN puts the plan in front of you before the query runs, and three of its columns answer almost every question people spend afternoons speculating about.
لست مضطرًا إلى تخمين أيُستخدم فهرس. فـEXPLAIN تضع الخطة أمامك قبل تشغيل الاستعلام، وثلاثة من أعمدتها تجيب كل سؤال تقريبًا يقضي الناس أصائل يتكهنون فيه.
-
8
Every index is paid for on every write / كل فهرس يُدفع ثمنه عند كل كتابة
Indexes are presented as free speed and are not. Each one is another sorted structure that has to be updated whenever a row is inserted, changed or removed — so a table with nine indexes does ten writes for every one you asked for.
تُقدَّم الفهارس سرعةً مجانية وليست كذلك. فكل واحد بنية مرتّبة أخرى يجب تحديثها كلما أُدخل صف أو غُيّر أو أُزيل — فالجدول بتسعة فهارس يؤدي عشر كتابات لكل واحدة طلبتها.
3 More than one person at onceأكثر من شخص في وقت واحد 4
-
9
Two writes that must both happen / كتابتان يجب أن تقعا معًا
Some operations are only correct as a whole. A transaction is how you tell the database that a group of statements is one thing — so that a crash between them leaves no trace instead of leaving half.
بعض العمليات لا تكون صحيحة إلا ككلٍّ. والمعاملة هي كيف تخبر قاعدة البيانات أن مجموعة عبارات شيء واحد — فيترك انهيارٌ بينها لا أثرًا بدل أن يترك نصفًا.
-
10
Two people, one row, one of them loses / شخصان، صفٌّ واحد، وأحدهما يخسر
Read a value, work something out, write it back. That sequence is correct alone and wrong the moment somebody else is doing it too — and the failure leaves no error, no log line and no sign that anything went missing.
اقرأ قيمة، واستنتج شيئًا، واكتبه. ذلك التتابع صحيح وحدك وخاطئ لحظة يفعله غيرك أيضًا — والإخفاق لا يترك خطأً ولا سطر سجل ولا علامة على أن شيئًا ضاع.
-
11
How much of other people you can see / كم ترى من الآخرين
Isolation is a dial, not a promise. Turning it up removes whole categories of wrong answer and costs throughput; turning it down does the opposite. Knowing where yours is set explains bugs that otherwise look impossible.
العزل قرصُ ضبط لا وعد. فرفعه يزيل أصنافًا كاملة من الأجوبة الخاطئة ويكلّف إنتاجية؛ وخفضه يفعل العكس. ومعرفة موضع قرصك تفسّر عللًا تبدو مستحيلة لولاها.
-
12
Waiting, and waiting for each other / الانتظار، وانتظار بعضهم بعضًا
Isolation is implemented with locks, and locks mean waiting. Most of the time that is invisible. Occasionally two transactions wait for each other in a circle, and the database has to kill one of them to get anything moving again.
العزل يُنفَّذ بالأقفال، والأقفال تعني انتظارًا. وذلك غير مرئي في معظم الوقت. وأحيانًا تنتظر معاملتان إحداهما الأخرى في دائرة، فيلزم قاعدة البيانات قتلُ إحداهما ليتحرك شيء ثانيةً.
4 When it gets bigحين يكبر 4
-
13
Page 900 is slower than page 1 / الصفحة 900 أبطأ من الصفحة 1
OFFSET is the pagination everybody writes and it gets slower the further in you go, because the database has to produce and discard every row it skips. There is another way to ask the same question that does not.
OFFSET هو الترقيم الذي يكتبه الجميع ويبطؤ كلما توغّلت، لأن على قاعدة البيانات إنتاج كل صف تتخطاه ثم رميه. وثمة طريقة أخرى لطرح السؤال نفسه لا تفعل ذلك.
-
14
ALTER TABLE on something people are using / ALTER TABLE على شيء يستخدمه الناس
The production course covered deploying a schema change safely in steps. This is the other half: what the database is doing during the step, why a statement that took a second locally can hold a table for twenty minutes, and how to find out before you run it.
غطّت دورة الإنتاج نشرَ تغيير مخطط بأمان على خطوات. وهذا النصف الآخر: ماذا تفعل قاعدة البيانات أثناء الخطوة، ولماذا قد تحجز عبارةٌ استغرقت ثانيةً محليًا جدولًا عشرين دقيقة، وكيف تعرف قبل تشغيلها.
-
15
The report that takes the site down / التقرير الذي يُسقط الموقع
Serving a page and answering a business question are different workloads with opposite shapes, and running both against one database means the second occasionally stops the first. The fix is separation, and it is cheaper than it sounds.
تقديم صفحة وإجابة سؤال عمل حِملان مختلفان بشكلين متعاكسين، وتشغيلهما على قاعدة بيانات واحدة يعني أن الثاني يوقف الأول أحيانًا. والعلاج الفصل، وهو أرخص مما يبدو.
-
16
Reading a schema and saying what will hurt / قراءة مخطط وقول ما سيؤلم
Everything in this course arrives as one skill: being handed a set of tables and being able to say, before anything is built on them, which decisions will be expensive and which will be impossible to undo.
كل ما في هذه الدورة يصل مهارةً واحدة: أن تُسلَّم مجموعة جداول وتستطيع القول، قبل أن يُبنى عليها شيء، أي القرارات ستكون باهظة وأيها سيستحيل نقضه.