{"id":34419,"date":"2019-10-31T21:58:13","date_gmt":"2019-10-31T18:58:13","guid":{"rendered":"https:\/\/prohoster.info\/blog\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql\/"},"modified":"2019-10-31T21:58:13","modified_gmt":"2019-10-31T18:58:13","slug":"ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql","status":"publish","type":"post","link":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql","title":{"rendered":"P\u00ebrdorim t\u00eb gjitha mund\u00ebsit\u00eb e indekseve n\u00eb PostgreSQL","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"P\u00ebrdorim t\u00eb gjitha mund\u00ebsit\u00eb e indekseve n\u00eb PostgreSQL\" src=\"\/wp-content\/uploads\/2019\/05\/34a92715e0cfaff2519d1aea460592ea.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\nN\u00eb bot\u00ebn e Postgres, indekset jan\u00eb jasht\u00ebzakonisht t\u00eb r\u00ebnd\u00ebsishme p\u00ebr navigimin e efektsh\u00ebm n\u00eb ruajtjen e baz\u00ebs s\u00eb t\u00eb dh\u00ebnave (e cila quhet \"heap\"). Postgres nuk mb\u00ebshtet klasterizimin p\u00ebr t\u00eb, dhe arkitektura MVCC \u00e7on n\u00eb akumulimin e shum\u00eb versioneve t\u00eb nj\u00ebjta t\u00eb t\u00eb nj\u00ebjt\u00ebs regjist\u00ebr. Prandaj, \u00ebsht\u00eb shum\u00eb e r\u00ebnd\u00ebsishme t\u00eb jeni n\u00eb gjendje t\u00eb krijoni dhe mbani indekset efektive p\u00ebr mb\u00ebshtetje t\u00eb aplikacioneve.<\/p>\n<p>Ju ofroj disa k\u00ebshilla p\u00ebr optimizimin dhe p\u00ebrmir\u00ebsimin e p\u00ebrdorimit t\u00eb indekseve.<\/p>\n<p><i>Sh\u00ebnim: k\u00ebrkesat e treguara m\u00eb posht\u00eb funksionojn\u00eb n\u00eb nj\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/devrimgunduz\/pagila\">most\u00ebr t\u00eb pandryshuar t\u00eb baz\u00ebs s\u00eb t\u00eb dh\u00ebnave pagila.<\/a><\/noindex>.<\/i><br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>P\u00ebrdorimi i indekseve mbuluese (Covering Indexes)<\/h3>\n<p>\nLe t\u00eb shqyrtojm\u00eb nj\u00eb k\u00ebrkes\u00eb p\u00ebr t\u00eb nxjerr\u00eb adresat e post\u00ebs elektronike p\u00ebr p\u00ebrdoruesit e pasivizuar. N\u00eb tabel\u00ebn <code>customer<\/code> ka nj\u00eb kolone <code>aktiv<\/code>, dhe k\u00ebrkesa rezulton e thjesht\u00eb:<\/p>\n<pre><code class=\"sql\">pagila=# EXPLAIN SELECT email FROM customer WHERE active=0;\n                        PLAN K\u00cbRKESASH\n-----------------------------------------------------------\n Skanim Sequent n\u00eb customer  (kosto=0.00..16.49 radh\u00eb=15 gjer\u00ebsi=32)\n   Filtri: (active = 0)\n(2 radh\u00eb)<\/code><\/pre>\n<p>\nK\u00ebrkesa th\u00ebrret gjith\u00eb sekuenc\u00ebn e skanimit t\u00eb tabel\u00ebs. <code>customer<\/code>Le t\u00eb krijojm\u00eb nj\u00eb indeks p\u00ebr kolon\u00ebn <code>aktiv<\/code>:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_cust1 ON customer(active);\nKRIJO IND\u00caKST\npagila=# EXPLAIN SELECT email FROM customer WHERE active=0;\n                                 PLAN K\u00cbRKESASH\n-----------------------------------------------------------------------------\n Skanim nga indeksi duke p\u00ebrdorur idx_cust1 mbi customer  (kosto=0.28..12.29 radh\u00eb=15 gjer\u00ebsi=32)\n   Kushti i Indeksit: (active = 0)\n(2 radh\u00eb)<\/code><\/pre>\n<p>\nKjo ndihmoi, skanimi i m\u00ebpassh\u00ebm u shnd\u00ebrrua n\u00eb \"<code>index scan<\/code>\". Kjo do t\u00eb thot\u00eb se Postgres do t\u00eb skanoj\u00eb indeksin \"<code>idx_cust1<\/code>\", dhe m\u00eb pas do t\u00eb vazhdoj\u00eb t\u00eb k\u00ebrkoj\u00eb n\u00eb grumbullin e tabel\u00ebs p\u00ebr t\u00eb lexuar vlerat e kolonave t\u00eb tjera (n\u00eb k\u00ebt\u00eb rast, kolon\u00ebn <code>email<\/code>), q\u00eb jan\u00eb t\u00eb nevojshme p\u00ebr k\u00ebrkes\u00eb.<\/p>\n<p>N\u00eb PostgreSQL 11 u prezantuan indekset mbuluese. Ato lejojn\u00eb t\u00eb p\u00ebrfshihen n\u00eb indeks nj\u00eb ose disa kolona shtes\u00eb \u2014 vlerat e tyre ruhen n\u00eb ruajtjen e t\u00eb dh\u00ebnave t\u00eb indeksit.<\/p>\n<p>N\u00ebse do t\u00eb kishim p\u00ebrdorur k\u00ebt\u00eb mund\u00ebsi dhe do t\u00eb kishim shtuar vler\u00ebn e post\u00ebs elektronike brenda indeksit, at\u00ebher\u00eb Postgres nuk do t\u00eb kishte nevoj\u00eb t\u00eb k\u00ebrkonte n\u00eb heap-in e tabel\u00ebs p\u00ebr vler\u00ebn. <code>email<\/code>T\u00eb shohim n\u00ebse kjo do t\u00eb funksionoj\u00eb:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_cust2 ON customer(active) INCLUDE (email);\nKRIJO IND\u00caKST\npagila=# EXPLAIN SELECT email FROM customer WHERE active=0;\n                                    PLAN K\u00cbRKESASH\n----------------------------------------------------------------------------------\n Skenimi vet\u00ebm nga indeksi duke p\u00ebrdorur idx_cust2 mbi customer  (kosto=0.28..12.29 radh\u00eb=15 gjer\u00ebsi=32)\n   Kushti i Indeksit: (active = 0)\n(2 radh\u00eb)<\/code><\/pre>\n<p>\n&#171;<code>Skanimi vet\u00ebm nga indeksi<\/code>\" na tregon se k\u00ebrkes\u00ebs tani i mjafton vet\u00ebm nj\u00eb indeks, q\u00eb ndihmon t\u00eb shmanget \u00e7do operacion i hyrjes\/daljes n\u00eb disqe p\u00ebr t\u00eb lexuar grumbullin e tabel\u00ebs.<\/p>\n<p>Sot zbulimi i treguesve jan\u00eb t\u00eb disponuesh\u00ebm vet\u00ebm p\u00ebr pem\u00ebt B. Megjithat\u00eb, n\u00eb k\u00ebt\u00eb rast, p\u00ebrpjekjet p\u00ebr mb\u00ebshtetje do t\u00eb jen\u00eb m\u00eb t\u00eb larta.<\/p>\n<h3>P\u00ebrdorimi i treguesve t\u00eb pjessh\u00ebm<\/h3>\n<p>\nTreguesit e pjessh\u00ebm indeksojn\u00eb vet\u00ebm nj\u00eb n\u00ebngrup t\u00eb rreshtave t\u00eb tabel\u00ebs. Kjo lejon t\u00eb kursehet hap\u00ebsira e treguesve dhe t\u00eb p\u00ebrshpejtohet skanimi.<\/p>\n<p>Supozoni se kemi nevoj\u00eb p\u00ebr t\u00eb marr\u00eb nj\u00eb list\u00eb t\u00eb adresave t\u00eb post\u00ebs elektronike t\u00eb klient\u00ebve tan\u00eb nga Kaliforni. K\u00ebrkesa do t\u00eb ishte si m\u00eb posht\u00eb:<\/p>\n<pre><code class=\"sql\">SELECT c.email FROM customer c\nJOIN address a ON c.address_id = a.address_id\nWHERE a.district = 'California';\n\u00e7ka ka nj\u00eb plan k\u00ebrkese q\u00eb p\u00ebrfshin skanimin e t\u00eb dyja tabelave q\u00eb jan\u00eb t\u00eb bashkuara:\npagila=# EXPLAIN SELECT c.email FROM customer c\npagila-# JOIN address a ON c.address_id = a.address_id\npagila-# WHERE a.district = 'California';\n                              PLANI I K\u00cbRKES\u00cbS\n----------------------------------------------------------------------\n Hash Join  (cost=15.65..32.22 rows=9 width=32)\n   Hash Cond: (c.address_id = a.address_id)\n   -&gt;  Seq Scan on customer c  (cost=0.00..14.99 rows=599 width=34)\n   -&gt;  Hash  (cost=15.54..15.54 rows=9 width=4)\n         -&gt;  Seq Scan on address a  (cost=0.00..15.54 rows=9 width=4)\n               Filtri: (district = 'California'::text)\n(6 rreshta)<\/code><\/pre>\n<p>\n\u00c7far\u00eb do t\u00eb na japin treguesit e zakonsh\u00ebm:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_address1 ON address(district);\nKRIJO TREGUES\npagila=# EXPLAIN SELECT c.email FROM customer c\npagila-# JOIN address a ON c.address_id = a.address_id\npagila-# WHERE a.district = 'California';\n                                      PLANI I K\u00cbRKES\u00cbS\n---------------------------------------------------------------------------------------\n Hash Join  (cost=12.98..29.55 rows=9 width=32)\n   Hash Cond: (c.address_id = a.address_id)\n   -&gt;  Seq Scan on customer c  (cost=0.00..14.99 rows=599 width=34)\n   -&gt;  Hash  (cost=12.87..12.87 rows=9 width=4)\n         -&gt;  Bitmap Heap Scan on address a  (cost=4.34..12.87 rows=9 width=4)\n               Rikonfirmo Kondit\u00ebn: (district = 'California'::text)\n               -&gt;  Bitmap Index Scan on idx_address1  (cost=0.00..4.34 rows=9 width=0)\n                     Kondita e Treguesit: (district = 'California'::text)\n(8 rreshta)<\/code><\/pre>\n<p>\nSkanimi <code>address<\/code> u z\u00ebvend\u00ebsua me skanimin e treguesit <code>idx_address1<\/code>, dhe pastaj u skanua grumbulli <code>address<\/code>.<\/p>\n<p>Duke qen\u00eb se kjo \u00ebsht\u00eb nj\u00eb k\u00ebrkes\u00eb e zakonshme dhe duhet optimizuar, mund t\u00eb p\u00ebrdorim nj\u00eb tregues t\u00eb pjessh\u00ebm, i cili indekson vet\u00ebm ato rreshta me adresat n\u00eb t\u00eb cilat distrikti <code>\u2018California\u2019<\/code>:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_address2 ON address(address_id) WHERE district='California';\nKRIJO TREGUES\npagila=# EXPLAIN SELECT c.email FROM customer c\npagila-# JOIN address a ON c.address_id = a.address_id\npagila-# WHERE a.district = 'California';\n                                           PLANI I K\u00cbRKES\u00cbS\n------------------------------------------------------------------------------------------------\n Hash Join  (cost=12.38..28.96 rows=9 width=32)\n   Hash Cond: (c.address_id = a.address_id)\n   -&gt;  Seq Scan on customer c  (cost=0.00..14.99 rows=599 width=34)\n   -&gt;  Hash  (cost=12.27..12.27 rows=9 width=4)\n         -&gt;  Index Only Scan duke p\u00ebrdorur idx_address2 on address a  (cost=0.14..12.27 rows=9 width=4)\n(5 rreshta)<\/code><\/pre>\n<p>\nTani k\u00ebrkesa lexon vet\u00ebm <code>idx_address2<\/code> dhe nuk prek tabel\u00ebn <code>address<\/code>.<\/p>\n<h3>P\u00ebrdorimi i treguesve me shum\u00eb vlera (Multi-Value Indexes)<\/h3>\n<p>\nDisa kolona q\u00eb duhet t\u00eb indeksohen mund t\u00eb mos p\u00ebrmbajn\u00eb tipin skalar t\u00eb t\u00eb dh\u00ebnave. Tipet e kolonave si <code>jsonb<\/code>, <code>arrays<\/code> dhe <code>tsvector<\/code> mund t\u00eb p\u00ebrmbajn\u00eb vlera t\u00eb shumta ose komplekse. N\u00ebse ju nevojitet t\u00eb indeksoni k\u00ebto kolona, zakonisht duhet t\u00eb k\u00ebrkoni n\u00eb t\u00eb gjitha vlerat e ve\u00e7anta n\u00eb k\u00ebto kolona.<\/p>\n<p>Le t\u00eb provojm\u00eb t\u00eb gjejm\u00eb titujt e t\u00eb gjith\u00eb filmeve q\u00eb p\u00ebrmbajn\u00eb skena nga dublat e d\u00ebshtuara. N\u00eb tabel\u00ebn <code>film<\/code> ka nj\u00eb kolon\u00eb tekstuale, e quajtur <code>special_features<\/code>. N\u00ebse filmi ka k\u00ebt\u00eb \"ve\u00e7ori t\u00eb ve\u00e7ant\u00eb\", at\u00ebher\u00eb n\u00eb kolon\u00eb ndodhet nj\u00eb element n\u00eb form\u00ebn e nj\u00eb array tekstual <code>Behind The Scenes<\/code>. P\u00ebr t\u00eb gjetur t\u00eb gjith\u00eb k\u00ebta filma na nevojitet t\u00eb zgjedhim t\u00eb gjitha rreshtat q\u00eb p\u00ebrmbajn\u00eb \"Behind The Scenes\" me <b>\u00e7do <\/b>vler\u00eb t\u00eb array-t <code>special_features<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT title FROM film WHERE special_features @&gt; '{\"Behind The Scenes\"}';<\/code><\/pre>\n<p>\nOperatori i p\u00ebrmbajtjes (containment operator) <code>@&gt;<\/code> kontrollon n\u00ebse ana e djatht\u00eb \u00ebsht\u00eb n\u00ebngrup i an\u00ebs s\u00eb majt\u00eb.<\/p>\n<p>Plani i k\u00ebrkes\u00ebs:<\/p>\n<pre><code class=\"sql\">pagila=# EXPLAIN SELECT title FROM film\npagila-# WHERE special_features @&gt; '{\"Behind The Scenes\"}';\n                           QUERY PLAN\n-----------------------------------------------------------------\n Seq Scan on film  (cost=0.00..67.50 rows=5 width=15)\n   Filter: (special_features @&gt; '{\"Behind The Scenes\"}'::text[])\n(2 rows)<\/code><\/pre>\n<p>\nI cili k\u00ebrkon nj\u00eb skanim t\u00eb plot\u00eb t\u00eb grumbullit me nj\u00eb kosto prej 67.<\/p>\n<p>Le t\u00eb shohim n\u00ebse na ndihmon nj\u00eb indeks i zakonsh\u00ebm B-tree:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_film1 ON film(special_features);\nCREATE INDEX\npagila=# EXPLAIN SELECT title FROM film\npagila-# WHERE special_features @&gt; '{\"Behind The Scenes\"}';\n                           QUERY PLAN\n-----------------------------------------------------------------\n Seq Scan on film  (cost=0.00..67.50 rows=5 width=15)\n   Filter: (special_features @&gt; '{\"Behind The Scenes\"}'::text[])\n(2 rows)<\/code><\/pre>\n<p>\nIndeksi nuk u shqyrtua fare. Indeksi B-tree nuk e kupton ekzistenc\u00ebn e elementeve t\u00eb ve\u00e7anta n\u00eb vlerat e indeksohshme.<\/p>\n<p>Na nevojitet nj\u00eb indeks GIN.<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX idx_film2 ON film USING GIN(special_features);\nCREATE INDEX\npagila=# EXPLAIN SELECT title FROM film\npagila-# WHERE special_features @&gt; '{\"Behind The Scenes\"}';\n                                QUERY PLAN\n---------------------------------------------------------------------------\n Bitmap Heap Scan on film  (cost=8.04..23.58 rows=5 width=15)\n   Recheck Cond: (special_features @&gt; '{\"Behind The Scenes\"}'::text[])\n   -&gt;  Bitmap Index Scan on idx_film2  (cost=0.00..8.04 rows=5 width=0)\n         Index Cond: (special_features @&gt; '{\"Behind The Scenes\"}'::text[])\n(4 rows)<\/code><\/pre>\n<p>\nIndeksi GIN mb\u00ebshtet p\u00ebrputhjen e vlerave t\u00eb ve\u00e7anta me vlerat komplekse t\u00eb indeksohshme, duke rezultuar n\u00eb nj\u00eb ulje t\u00eb kostos s\u00eb planit t\u00eb k\u00ebrkes\u00ebs p\u00ebr m\u00eb shum\u00eb se dyfish.<\/p>\n<h3>Shk\u00ebputemi nga dublikimi i indekseve<\/h3>\n<p>\nIndekset grumbullohen me kalimin e koh\u00ebs, dhe ndonj\u00ebher\u00eb indeksi i ri mund t\u00eb p\u00ebrmbaj\u00eb t\u00eb nj\u00ebjtin p\u00ebrkufizim si nj\u00eb nga ato t\u00eb m\u00ebparshme. P\u00ebr t\u00eb marr\u00eb p\u00ebrcaktime SQL q\u00eb jan\u00eb m\u00eb t\u00eb lexueshme p\u00ebr njer\u00ebzit, mund t\u00eb p\u00ebrdorni pamjen kataloguese <code>pg_indexes<\/code>. Gjithashtu do t\u00eb jeni n\u00eb gjendje t\u00eb gjeni leht\u00ebsisht t\u00eb nj\u00ebjtat p\u00ebrkufizime:<\/p>\n<pre><code class=\"sql\"> SELECT array_agg(indexname) AS indexes, replace(indexdef, indexname, '') AS defn\n    FROM pg_indexes\nGROUP BY defn\n  HAVING count(*) &gt; 1;\nDhe ja rezultati kur ekzekutohet n\u00eb baz\u00ebn e t\u00eb dh\u00ebnave pagila standard:\npagila=#   SELECT array_agg(indexname) AS indexes, replace(indexdef, indexname, '') AS defn\npagila-#     FROM pg_indexes\npagila-# GROUP BY defn\npagila-#   HAVING count(*) &gt; 1;\n                                indexes                                 |                                defn\n------------------------------------------------------------------------+------------------------------------------------------------------\n {payment_p2017_01_customer_id_idx,idx_fk_payment_p2017_01_customer_id} | CREATE INDEX  ON public.payment_p2017_01 USING btree (customer_id\n {payment_p2017_02_customer_id_idx,idx_fk_payment_p2017_02_customer_id} | CREATE INDEX  ON public.payment_p2017_02 USING btree (customer_id\n {payment_p2017_03_customer_id_idx,idx_fk_payment_p2017_03_customer_id} | CREATE INDEX  ON public.payment_p2017_03 USING btree (customer_id\n {idx_fk_payment_p2017_04_customer_id,payment_p2017_04_customer_id_idx} | CREATE INDEX  ON public.payment_p2017_04 USING btree (customer_id\n {payment_p2017_05_customer_id_idx,idx_fk_payment_p2017_05_customer_id} | CREATE INDEX  ON public.payment_p2017_05 USING btree (customer_id\n {idx_fk_payment_p2017_06_customer_id,payment_p2017_06_customer_id_idx} | CREATE INDEX  ON public.payment_p2017_06 USING btree (customer_id\n(6 radh\u00eb)\n<\/code><\/pre>\n<p><\/p>\n<h3>Indekset e Superset<\/h3>\n<p>\nMund t\u00eb ndodh\u00eb q\u00eb t\u00eb keni shum\u00eb indekse, nj\u00eb nga t\u00eb cilat indekson nj\u00eb mbiqend\u00ebr t\u00eb kolonave q\u00eb indeksojn\u00eb indekse t\u00eb tjera. Kjo mund t\u00eb jet\u00eb e d\u00ebshirueshme ose jo - mbiqendra mund t\u00eb \u00e7oj\u00eb n\u00eb skanimin vet\u00ebm p\u00ebrmes indekseve, q\u00eb \u00ebsht\u00eb mir\u00eb, por mund t\u00eb z\u00ebr\u00eb shum\u00eb hap\u00ebsir\u00eb, ose k\u00ebrkesa p\u00ebr optimizimin e s\u00eb cil\u00ebs ishte parashikuar kjo mbiqend\u00ebr, tashm\u00eb nuk p\u00ebrdoret m\u00eb.<\/p>\n<p>N\u00ebse ju nevojitet t\u00eb automatizoni identifikimin e till\u00eb t\u00eb indekseve, mund t\u00eb filloni me <noindex><a rel=\"nofollow\" href=\"https:\/\/www.postgresql.org\/docs\/current\/catalog-pg-index.html\">pg_index<\/a><\/noindex> nga tabela <code>pg_catalog<\/code>.<\/p>\n<h3>Indekset e pa p\u00ebrdorura<\/h3>\n<p>\nMe zhvillimin e aplikacioneve q\u00eb p\u00ebrdorin baza t\u00eb dh\u00ebnash, zhvillohen gjithashtu edhe k\u00ebrkesat q\u00eb ato p\u00ebrdorin. Indekset e m\u00ebparshme t\u00eb shtuar mund t\u00eb mos p\u00ebrdoren m\u00eb nga asnj\u00eb k\u00ebrkes\u00eb. Gjat\u00eb \u00e7do skanimi t\u00eb indeksit, ai sh\u00ebnohet nga menaxheri i statistikave, dhe n\u00eb pamjen e sistemit <code>pg_stat_user_indexes<\/code> mund t\u00eb shihni vler\u00ebn <code>idx_scan<\/code>, e cila \u00ebsht\u00eb nj\u00eb num\u00ebrues kumulativ. Ndjekja e k\u00ebtij vler\u00ebsimi p\u00ebr nj\u00eb periudh\u00eb kohe (p.sh., nj\u00eb muaj) do t\u00eb ofroj\u00eb nj\u00eb pasqyr\u00eb t\u00eb mir\u00eb mbi cilat indekse nuk p\u00ebrdoren dhe mund t\u00eb fshihen.<\/p>\n<p>K\u00ebtu \u00ebsht\u00eb nj\u00eb k\u00ebrkes\u00eb p\u00ebr t\u00eb marr\u00eb num\u00ebruesit aktual\u00eb t\u00eb skanimit t\u00eb t\u00eb gjitha indekseve n\u00eb skem\u00ebn <code>\u2018public\u2019<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT relname, indexrelname, idx_scan\nFROM   pg_catalog.pg_stat_user_indexes\nWHERE  schemaname = 'public';\nme dalje t\u00eb till\u00eb:\npagila=# SELECT relname, indexrelname, idx_scan\npagila-# FROM   pg_catalog.pg_stat_user_indexes\npagila-# WHERE  schemaname = 'public'\npagila-# LIMIT  10;\n    relname    |    indexrelname    | idx_scan\n---------------+--------------------+----------\n customer      | customer_pkey      |    32093\n actor         | actor_pkey         |     5462\n address       | address_pkey       |      660\n category      | category_pkey      |     1000\n city          | city_pkey          |      609\n country       | country_pkey       |      604\n film_actor    | film_actor_pkey    |        0\n film_category | film_category_pkey |        0\n film          | film_pkey          |    11043\n inventory     | inventory_pkey     |    16048\n(10 rows)<\/code><\/pre>\n<p><\/p>\n<h3>Rikrijimi i indekseve me m\u00eb pak bllokime<\/h3>\n<p>\nHer\u00eb pas here indekset duhet t\u00eb rikrijohen, p\u00ebr shembull, kur ato zmadhohen n\u00eb dimensione, dhe rikrijimi mund t\u00eb p\u00ebrshpejtoj\u00eb skanimin. Gjithashtu, indekset mund t\u00eb d\u00ebmtohen. Ndryshimi i parametrave t\u00eb indekseve gjithashtu mund t\u00eb k\u00ebrkoj\u00eb rikrijimin e tyre.<\/p>\n<h3>Aktivizimi i krijimit t\u00eb indekseve paralel<\/h3>\n<p>\nN\u00eb PostgreSQL 11, krijimi i indeksi B-Tree \u00ebsht\u00eb konkurent. P\u00ebr t\u00eb p\u00ebrshpejtuar procesin e krijimit, mund t\u00eb p\u00ebrdoren disa pun\u00ebtor\u00eb q\u00eb funksionojn\u00eb paralel. Megjithat\u00eb, sigurohuni q\u00eb k\u00ebta parametra konfigurimi jan\u00eb vendosur sakt\u00eb:<\/p>\n<pre><code class=\"sql\">SET max_parallel_workers = 32;\nSET max_parallel_maintenance_workers = 16;<\/code><\/pre>\n<p>\nVlerat e parazgjedhura jan\u00eb shum\u00eb t\u00eb vogla. Idealisht, k\u00ebto numra duhet t\u00eb rriten s\u00eb bashku me numrin e nyjeve t\u00eb procesorit. M\u00eb shum\u00eb lexoni n\u00eb <noindex><a rel=\"nofollow\" href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-ASYNC-BEHAVIOR\">dokumentacionin<\/a><\/noindex>.<\/p>\n<h3>Krijimi i indekseve n\u00eb sfond<\/h3>\n<p>\nMund t\u00eb krijoni nj\u00eb indeks n\u00eb sfond duke p\u00ebrdorur parametrin <code>CONCURRENTLY<\/code> komandave <code>KRIJO IND\u00cbKS<\/code>:<\/p>\n<pre><code class=\"sql\">pagila=# CREATE INDEX CONCURRENTLY idx_address1 ON address(district);\nCREATE INDEX<\/code><\/pre>\n<p>Kjo procedur\u00eb e krijimit t\u00eb indeksit \u00ebsht\u00eb ndryshe nga e zakonshmja n\u00eb at\u00eb q\u00eb ajo nuk k\u00ebrkon bllokimin e tabel\u00ebs, dhe k\u00ebshtu nuk bllokon operacionet e shkrimit. Nga ana tjet\u00ebr, ajo merr m\u00eb shum\u00eb koh\u00eb dhe konsumon m\u00eb shum\u00eb burime.<\/p>\n<p>Postgres ofron shum\u00eb mund\u00ebsi fleksible p\u00ebr krijimin e indekseve dhe m\u00ebnyra p\u00ebr t\u00eb zgjidhur \u00e7do rast t\u00eb ve\u00e7ant\u00eb, si dhe ofron m\u00ebnyra p\u00ebr t\u00eb menaxhuar baz\u00ebn e t\u00eb dh\u00ebnave p\u00ebr rastet e rritjes eksplozive t\u00eb aplikacionit tuaj. Shpresojm\u00eb q\u00eb k\u00ebto k\u00ebshilla t'ju ndihmojn\u00eb t\u00eb b\u00ebni k\u00ebrkesat m\u00eb t\u00eb shpejta dhe baz\u00ebn e t\u00eb dh\u00ebnave gati p\u00ebr t'u skalitur.<br \/>\n<br \/>Burimi: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/453046\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412 \u043c\u0438\u0440\u0435 Postgres \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u0435\u0433\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u00ab\u043a\u0443\u0447\u0430\u00bb, heap). Postgres \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 MVCC \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0432\u0435\u0440\u0441\u0438\u0439 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043e\u0440\u0442\u0435\u0436\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":25931,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-34419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0412 \u043c\u0438\u0440\u0435 Postgres \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"sq_AL\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432 PostgreSQL | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0412 \u043c\u0438\u0440\u0435 Postgres \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T18:58:13+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T18:58:13+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Shfryt\u00ebzojm\u00eb t\u00eb gjitha mund\u00ebsit\u00eb e indekseve n\u00eb PostgreSQL | ProHoster","description":"N\u00eb bot\u00ebn e Postgres, indekset jan\u00eb jasht\u00ebzakonisht t\u00eb r\u00ebnd\u00ebsish\u00ebm p\u00ebr.","canonical_url":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"sq_AL","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432 PostgreSQL | ProHoster","og:description":"\u0412 \u043c\u0438\u0440\u0435 Postgres \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f.","og:url":"https:\/\/prohoster.info\/sq\/blog\/administrirovanie\/ispolzuem-vse-vozmozhnosti-indeksov-v-postgresql","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T18:58:13+00:00","article:modified_time":"2019-10-31T18:58:13+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"34419","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-21 19:13:20","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 13:52:22","updated":"2026-01-21 19:13:20","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/34419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/comments?post=34419"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/34419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/media\/25931"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/media?parent=34419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/categories?post=34419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/tags?post=34419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}