jsonb: متى وكيف
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
use jsonb for flexible attributes without abandoning the schema.
الموضوعات المخطط لها
- Good for sparse, varying attributes (product specs per category) and stored external payloads.
- Not a way to avoid designing the schema: keep ids, foreign keys, and frequently filtered fields as real columns.
- Query with
->,->>,@>; index with GIN (jsonb_path_opsfor containment) or a B-tree expression index on one key. - Updating one key rewrites the whole value; large frequently updated documents are costly.
تفاصيل المخطط المبدئي
عرض عملي
CREATE INDEX idx_product_attrs ON product USING gin (attrs jsonb_path_ops);
SELECT id FROM product WHERE attrs @> '{"color":"red"}';اختبر فهمك
Which fields should not live only in jsonb?
أظهر الإجابة
Keys, foreign keys, and fields used in joins and frequent filters.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.