← Back to PostgreSQL Course | Chapter 9: Indexes & Performance | Lesson 2 of 7

Indexes के प्रकार

PostgreSQL में कई index types हैं, हर एक अलग-अलग तरह की queries के लिए suit करता है।

In this page:

  1. Indexes के Types
Syntax
sql
CREATE INDEX index_name ON table_name USING btree (column);
CREATE INDEX index_name ON table_name USING gin (column);

Indexes के Types

equality और ranges के लिए B-tree default है। Hash सिर्फ equality handle करता है। GIN composite values index करता है जैसे JSONB, arrays, और full-text search।

GiST geometry और range types support करता है, SP-GiST partitioned data, और BRIN huge, naturally ordered tables के लिए tiny summaries store करता है। Partial और expression indexes narrow करते हैं कि क्या index होता है।

Note: JSONB और array containment queries के लिए GIN इस्तेमाल करें।

उदाहरण: Types of indexes

bash
shop=# CREATE INDEX idx_orders_created ON orders (created_at);                     -- B-tree
shop=# CREATE INDEX idx_docs_data ON docs USING GIN (data);                         -- JSONB
shop=# CREATE INDEX idx_places_geo ON places USING GIST (location);                 -- geometry
shop=# CREATE INDEX idx_log_ts ON logs USING BRIN (ts);                             -- huge ordered table
shop=# CREATE INDEX idx_active ON users (email) WHERE active;                       -- partial
shop=# CREATE INDEX idx_lower_email ON users (lower(email));                        -- expression

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. जहाँ GIN चाहिए वहाँ B-tree इस्तेमाल करना
  2. huge time-ordered tables के लिए BRIN ignore करना
  3. redundant indexes बनाना
चैप्टर सारांश
  • B-tree default है
  • JSONB, arrays, और full-text के लिए GIN
  • Geometry और ranges के लिए GiST
  • Huge ordered tables के लिए BRIN
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.