{"id":278655,"date":"2016-04-20T11:55:02","date_gmt":"2016-04-20T07:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=278655"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=278655","title":{"rendered":"\u041e\u0431\u044a\u044f\u0441\u043d\u044f\u044f \u043d\u0435\u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c\u043e\u0435. \u0427\u0430\u0441\u0442\u044c 5"},"content":{"rendered":"<p>       <i>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043a PG Day\u201916 \u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 PostgreSQL.<\/i><\/p>\n<p>  \u0412 <a href=\"https:\/\/habrahabr.ru\/post\/275851\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/276973\/\">\u043f\u043e\u0441\u0442\u0430\u0445<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/279255\/\">\u044d\u0442\u043e\u0439<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/281036\/\">\u0441\u0435\u0440\u0438\u0438<\/a> \u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 EXPLAIN \u0438 \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 (\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\/\u0443\u0437\u0435\u043b).<\/p>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u00ab\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044e X\u00bb, \u0430 \u043d\u0435 \u00ab\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044e Y\u00bb.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/432\/20b\/3dc\/43220b3dc23746abb0b2c49999a700dc.jpg\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a PostgreSQL \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435. \u041a\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435?<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445:<\/p>\n<pre><code class=\"sql\">SELECT * FROM table WHERE column = some_value; <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 some_value, \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 (\u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e) \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430.<\/p>\n<p>  \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b (\u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u2013 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0438\u0434\u0435\u044f.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"sql\">create table test ( all_the_same int4, almost_unique int4 ); CREATE TABLE   insert into test ( all_the_same, almost_unique )     select 123, random() * 1000000 from generate_series(1,100000); INSERT 0 100000 <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0430 100,000 \u0441\u0442\u0440\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u00aball_the_same\u00bb \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (123), \u0430 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 almost_unique, \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0447\u0442\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d:<\/p>\n<pre><code class=\"sql\">select count(*), count(distinct almost_unique) from test;  count  | count  --------+-------  100000 | 95142 (1 row) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0440\u0430\u0432\u043d\u044b\u043c\u0438, \u044f \u0441\u043e\u0437\u0434\u0430\u043c \u0434\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u0430:<\/p>\n<pre><code class=\"sql\">create index i1 on test (all_the_same); CREATE INDEX   create index i2 on test (almost_unique); CREATE INDEX <\/code><\/pre>\n<p>  \u041e\u043a, \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0433\u043e\u0442\u043e\u0432\u0430. \u0410 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u043f\u043b\u0430\u043d\u043e\u0432?<\/p>\n<pre><code class=\"sql\">explain select * from test where all_the_same = 123;                          QUERY PLAN                          ------------------------------------------------------------  Seq Scan on test  (cost=0.00..1693.00 rows=100000 width=8)    Filter: (all_the_same = 123) (2 rows)   explain select * from test where almost_unique = 123;                           QUERY PLAN                            ---------------------------------------------------------------  Index Scan using i2 on test  (cost=0.29..8.31 rows=1 width=8)    Index Cond: (almost_unique = 123) (2 rows) <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0441\u0434\u0435\u043b\u0430\u043b \u043c\u0443\u0434\u0440\u044b\u0439 \u0432\u044b\u0431\u043e\u0440. \u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043e\u0446\u0435\u043d\u043e\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u00abrows=\u00bb. \u041e\u0442\u043a\u0443\u0434\u0430 \u043e\u043d \u0437\u043d\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441?<br \/>  \u041e\u0442\u0432\u0435\u0442 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 <a href=\"http:\/\/www.postgresql.org\/docs\/current\/interactive\/sql-analyze.html\">ANALYZE<\/a> \u0438\u043b\u0438 <a href=\"http:\/\/www.postgresql.org\/docs\/current\/interactive\/sql-vacuum.html\">VACUUM ANALYZE<\/a>.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00abANALYZE\u00bb, \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 \u00ab\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446\u00bb (random sample) (\u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435) \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0427\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430, \u0433\u0434\u0435 \u043e\u043d\u0430, \u0438 \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0435\u0451 \u0443\u0432\u0438\u0434\u0435\u0442\u044c? \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u0435\u043c:<\/p>\n<pre><code class=\"sql\">select * from pg_statistic where starelid = 'test'::regclass; -[ RECORD 1 ]----------------------------------------------------------------------------- starelid    | 16882 staattnum   | 1 stainherit  | f stanullfrac | 0 stawidth    | 4 stadistinct | 1 stakind1    | 1 stakind2    | 3 stakind3    | 0 stakind4    | 0 stakind5    | 0 staop1      | 96 staop2      | 97 staop3      | 0 staop4      | 0 staop5      | 0 stanumbers1 | {1} stanumbers2 | {1} stanumbers3 | [null] stanumbers4 | [null] stanumbers5 | [null] stavalues1  | {123} stavalues2  | [null] stavalues3  | [null] stavalues4  | [null] stavalues5  | [null] -[ RECORD 2 ]----------------------------------------------------------------------------- starelid    | 16882 staattnum   | 2 stainherit  | f stanullfrac | 0 stawidth    | 4 stadistinct | -0.92146 stakind1    | 1 stakind2    | 2 stakind3    | 3 stakind4    | 0 stakind5    | 0 staop1      | 96 staop2      | 97 staop3      | 97 staop4      | 0 staop5      | 0 stanumbers1 | {0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05} stanumbers2 | [null] stanumbers3 | {-0.000468686} stanumbers4 | [null] stanumbers5 | [null] stavalues1  | {21606,27889,120502,289914,417495,951355,283,1812,3774,6028,6229,10372,12234,13291,18309,18443,21758,22565,26634,28392,28413,31208,32890,36563,39277,40574,44527,49954,53344,53863,56492,56715,60856,62993,64294,65275,65355,68353,71194,74718,77205,82096,82783,84764,85301,87498,90990,94043,97304,98779,101181,103700,103889,106288,108562,110796,113154,117850,121578,122643,123874,126299,129236,129332,129512,134430,134980,136987,137368,138175,139001,141519,142934,143432,143707,144501,148633,152481,154327,157067,157799,162437,164072,164337,165942,167611,170319,171047,177383,184134,188702,189005,191786,192718,196330,197851,199457,202652,202689,205983} stavalues2  | {2,10560,20266,31061,40804,50080,59234,69240,79094,89371,99470,109557,119578,130454,140809,152052,162656,173855,183914,194263,204593,214876,224596,233758,243246,253552,264145,273855,283780,294475,303972,314544,324929,335008,346169,356505,367395,376639,387302,397004,407093,416615,426646,436146,445701,455588,466463,475910,485228,495434,505425,515853,525374,534824,545387,554794,563591,573721,584021,593368,602935,613238,623317,633947,643431,653397,664177,673976,684042,694791,703922,714113,724602,735848,745596,754477,764171,772535,781924,791652,801703,812487,822196,831618,841665,850722,861532,872067,881570,891654,901595,910975,921698,931785,940716,950623,960551,970261,979855,989540,999993} stavalues3  | [null] stavalues4  | [null] stavalues5  | [null] <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 (pg_statistic), \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043e\u043f\u0438\u0441\u0430\u043d\u0430 <a href=\"http:\/\/www.postgresql.org\/docs\/current\/interactive\/catalog-pg-statistic.html\">\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u0430. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043e\u0447\u0435\u043d\u044c \u0442\u043e\u0447\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 <a href=\"http:\/\/git.postgresql.org\/gitweb\/?p=postgresql.git;a=blob;f=src\/include\/catalog\/pg_statistic.h\">\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445<\/a>, \u043d\u043e \u044d\u0442\u043e (\u043e\u0431\u044b\u0447\u043d\u043e) \u043d\u0435 \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 view \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u043e\u043b\u0435\u0435 \u00ab\u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c\u00bb \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"sql\">select * from pg_stats where tablename = 'test'; -[ RECORD 1 ]----------+------------------------------------------------------------------ schemaname             | public tablename              | test attname                | all_the_same inherited              | f null_frac              | 0 avg_width              | 4 n_distinct             | 1 most_common_vals       | {123} most_common_freqs      | {1} histogram_bounds       | [null] correlation            | 1 most_common_elems      | [null] most_common_elem_freqs | [null] elem_count_histogram   | [null] -[ RECORD 2 ]----------+------------------------------------------------------------------ schemaname             | public tablename              | test attname                | almost_unique inherited              | f null_frac              | 0 avg_width              | 4 n_distinct             | -0.92146 most_common_vals       | {21606,27889,120502,289914,417495,951355,283,1812,3774,6028,6229,10372,12234,13291,18309,18443,21758,22565,26634,28392,28413,31208,32890,36563,39277,40574,44527,49954,53344,53863,56492,56715,60856,62993,64294,65275,65355,68353,71194,74718,77205,82096,82783,84764,85301,87498,90990,94043,97304,98779,101181,103700,103889,106288,108562,110796,113154,117850,121578,122643,123874,126299,129236,129332,129512,134430,134980,136987,137368,138175,139001,141519,142934,143432,143707,144501,148633,152481,154327,157067,157799,162437,164072,164337,165942,167611,170319,171047,177383,184134,188702,189005,191786,192718,196330,197851,199457,202652,202689,205983} most_common_freqs      | {0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05} histogram_bounds       | {2,10560,20266,31061,40804,50080,59234,69240,79094,89371,99470,109557,119578,130454,140809,152052,162656,173855,183914,194263,204593,214876,224596,233758,243246,253552,264145,273855,283780,294475,303972,314544,324929,335008,346169,356505,367395,376639,387302,397004,407093,416615,426646,436146,445701,455588,466463,475910,485228,495434,505425,515853,525374,534824,545387,554794,563591,573721,584021,593368,602935,613238,623317,633947,643431,653397,664177,673976,684042,694791,703922,714113,724602,735848,745596,754477,764171,772535,781924,791652,801703,812487,822196,831618,841665,850722,861532,872067,881570,891654,901595,910975,921698,931785,940716,950623,960551,970261,979855,989540,999993} correlation            | -0.000468686 most_common_elems      | [null] most_common_elem_freqs | [null] elem_count_histogram   | [null] <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e. \u0422\u0430\u043a \u043a\u0430\u043a\u0438\u0435 \u0436\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u044e\u0434\u0430 \u043f\u043e\u0447\u0435\u0440\u043f\u043d\u0443\u0442\u044c?<\/p>\n<p>  \u0421\u0442\u043e\u043b\u0431\u0446\u044b schemaname, tablename \u0438 attname \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c\u0438. Inherited \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043b\u044e\u0431\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u0441\u0442\u043e\u043b\u0431\u0435\u0446.<\/p>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<pre><code class=\"sql\">create table z () inherits (test); <\/code><\/pre>\n<p>  \u0410 \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 z \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b test \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u0431\u044b \u00abinherited = true\u00bb.<\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<ul>\n<li>null_frac \u2014 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0435. \u042d\u0442\u043e \u0434\u043e\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442 0 \u0434\u043e 1.<\/li>\n<li>avg_width \u2014 \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0448\u0438\u0440\u0438\u043d\u0430 (\u043f\u0440\u0438\u043c. \u043f\u0435\u0440.: \u0440\u0430\u0437\u043c\u0435\u0440) \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0435. \u042d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0435\u0441\u043b\u0438 \u0448\u0438\u0440\u0438\u043d\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u0430 (\u043a\u0430\u043a \u0443 int4 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435), \u0430 \u0432\u043e\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u043e\u0439 (\u043a\u0430\u043a \u0443 text\/varchar\/numeric) \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.<\/li>\n<li>n_distinct \u2014 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f (1+), \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e (\u043d\u0435 \u0434\u043e\u043b\u044f!) \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c all_the_same, \u0433\u0434\u0435 n_distinct \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0440\u0430\u0432\u043d\u0430 1. \u0410 \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f, \u0442\u043e \u0441\u043c\u044b\u0441\u043b \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f: n_distinct \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0430\u044f \u0434\u043e\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 almost_unique \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e 92.146% \u0441\u0442\u0440\u043e\u043a \u0438\u043c\u0435\u044e\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0447\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 95.142%, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0440\u0430\u043d\u0435\u0435). \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0432\u0435\u0440\u043d\u044b \u0438\u0437-\u0437\u0430 \u0442\u043e\u0439 \u0448\u0442\u0443\u043a\u0438 \u0441 \u00ab\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c\u00bb, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0438 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e.<\/li>\n<li>most_common_vals \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/li>\n<li>most_common_freqs \u2014 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 most_common_vals \u2014 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 1 (\u043d\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 most_common_vals). \u0417\u0434\u0435\u0441\u044c, \u0432 almost_unique, \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u00ab\u0434\u0443\u043c\u0430\u0435\u0442\u00bb, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 21606, 27889, 120502, 289914, 417495, 951355 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0432\u043e \u0432\u0441\u0451\u043c \u0432\u0438\u043d\u043e\u0432\u0430\u0442 \u044d\u0444\u0444\u0435\u043a\u0442 \u00ab\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0446\u0430\u00bb.<\/li>\n<li>histogram_bounds \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0438\u0442 (\u0438\u043b\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u043b\u0438\u0442\u044c \u2014 \u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0451 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u00ab\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446\u00bb) \u0432\u0435\u0441\u044c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0442\u0440\u043e\u043a. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a almost_unique \u043c\u0435\u0436\u0434\u0443 2 \u0438 10560 \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 (\u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435), \u043a\u0430\u043a \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a almost_unique \u043c\u0435\u0436\u0434\u0443 931785 \u0438 940716.<\/li>\n<li>correlation \u2014 \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430, \u043e\u043d\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u042d\u0442\u0430 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043e\u0442 -1 \u0434\u043e 1, \u0438 \u0447\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043e\u043d\u0430 \u043a -1\/1, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u00abCLUSTER test using i2\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 almost_unique, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044e 0.919358 \u2014 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c -0.000468686. <br \/>  most_common_elems, most_common_elem_freqs \u0438 elem_count_histogram \u0442\u0430\u043a\u0438\u0435 \u0436\u0435, \u043a\u0430\u043a most_common_vals, most_common_freqs \u0438 histogram_bounds, \u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0442\u043e \u0435\u0441\u0442\u044c, arrays, tsvectors \u0438 alike).<\/li>\n<\/ul>\n<p>  \u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, PostgreSQL \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e \u043b\u044e\u0431\u043e\u0439 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0440\u0435\u0448\u0438\u0442\u044c, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: seq scan, index scan \u0438\u043b\u0438 bitmap index scan. \u0410 \u043f\u0440\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u2014 \u043a\u0430\u043a\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435: Hash Join, Merge Join \u0438\u043b\u0438, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, Nested Loop.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c: \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0448\u0438\u0440\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445 most_common_vals\/most_common_freqs\/histogram_bounds \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u0438\u0445 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e?<\/p>\n<p>  \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 \u2014 \u0432\u0441\u0451 \u0434\u0435\u043b\u043e \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445. \u0412 postgresql.conf \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e default_statistics_target. \u042d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441\u0443, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u044d\u0442\u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0432\u043d\u043e 100. \u041d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e. \u0412\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 postgresql.conf, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"sql\">alter table test alter column almost_unique set statistics 5; <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f ALTER (\u0438 ANALYZE) \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 pg_stats \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u043a\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f:<\/p>\n<pre><code class=\"sql\">select * from pg_stats where tablename = 'test' and not inherited and attname = 'almost_unique'; -[ RECORD 1 ]----------+--------------------------------------------------------- schemaname             | public tablename              | test attname                | almost_unique inherited              | f null_frac              | 0 avg_width              | 4 n_distinct             | -0.92112 most_common_vals       | {114832,3185,3774,6642,11984} most_common_freqs      | {0.0001,6.66667e-05,6.66667e-05,6.66667e-05,6.66667e-05} histogram_bounds       | {2,199470,401018,596414,798994,999964} correlation            | 1 most_common_elems      | [null] most_common_elem_freqs | [null] elem_count_histogram   | [null] <\/code><\/pre>\n<p>  \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 statistic target \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u044d\u0444\u0444\u0435\u043a\u0442.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0443. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043e\u0442\u043a\u0430\u0447\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0432\u043d\u0451\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ALTER TABLE:<\/p>\n<pre><code class=\"sql\">alter table test alter column almost_unique set statistics -1; <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"sql\">$ analyze verbose test; INFO:  analyzing &quot;public.test&quot; INFO:  &quot;test&quot;: scanned 443 of 443 pages, containing 100000 live rows and 0 dead rows; 30000 rows in sample, 100000 estimated total rows ANALYZE   $ alter table test alter column almost_unique set statistics 10; ALTER TABLE   $ alter table test alter column all_the_same set statistics 10; ALTER TABLE   $ analyze verbose test; INFO:  analyzing &quot;public.test&quot; INFO:  &quot;test&quot;: scanned 443 of 443 pages, containing 100000 live rows and 0 dead rows; 3000 rows in sample, 100000 estimated total rows ANALYZE <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 analyze \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0432\u0441\u0435\u0433\u043e 3000 \u0441\u0442\u0440\u043e\u043a, \u0430 \u043d\u0435 30000, \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439.<\/p>\n<p>  \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u00ab\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437\u0435\u0446\u00bb.<\/p>\n<p>  \u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u043c\u0435\u0440\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u043c \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0443\u043c\u043d\u0435\u0435.<\/p>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u043d \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 (\u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e: \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u2014 \u044d\u0442\u043e 8\u043a\u0411 \u0434\u0430\u043d\u043d\u044b\u0445). \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d\u043d\u043e? 300 * statistics_target.<\/p>\n<p>  \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 default_statistics_target = 100 \u043e\u043d \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u0442 30000 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 (\u0432 \u043c\u043e\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0445 \u0432\u0441\u0435).<\/p>\n<p>  \u0418\u0437 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 ANALYZE \u0431\u0435\u0440\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0436\u0438\u0432\u044b\u0445 \u0438 \u043c\u0451\u0440\u0442\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445. \u0417\u0430\u0442\u0435\u043c \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u043e\u0431\u0440\u0430\u0437\u0446\u0435 \u0441\u0442\u0440\u043e\u043a \u2014 \u0441\u043d\u043e\u0432\u0430 300 * statistics target \u2014 \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u044b\u043b\u043e 100,000 \u0441\u0442\u0440\u043e\u043a, \u043d\u043e \u0441 default_statistics_target = 100 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u0442\u044c \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430. \u0410, \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f statistics target, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0435\u0449\u0451 \u043c\u0435\u043d\u044c\u0448\u0435 \u2014 \u0432\u0441\u0435\u0433\u043e 3000.<\/p>\n<p>  \u0412\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u043a\u0430\u0437\u0430\u0442\u044c: \u041e\u041a, \u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043d\u0435\u0442\u043e\u0447\u043d\u0430\u044f. \u041c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0443\u043f\u0435\u0440-\u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b\u043e\u0441\u044c \u043d\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u044b \u043f\u0440\u0430\u0432\u044b. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u0425\u043e\u0442\u044f \u0438 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e. \u0412\u044b \u0431\u0435\u0440\u0435\u0442\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445. \u0428\u0430\u043d\u0441\u044b, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 x% \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445, \u043d\u0438\u0447\u0442\u043e\u0436\u043d\u043e \u043c\u0430\u043b\u044b.<\/p>\n<p>  \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0437\u0430\u043f\u0443\u0441\u043a analyze \u0431\u0443\u0434\u0435\u0442 \u00ab\u043b\u043e\u043c\u0430\u0442\u044c\u00bb \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u043c, \u0438 \u0432\u044b\u0439\u0434\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b (\u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u2014 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0432 most_common_vals \u043d\u0435 \u0442\u0430\u043a\u0438\u0435 \u0443\u0436 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\/\u0441\u0442\u0440\u043e\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0443\u0432\u0438\u0434\u0435\u0442\u044c). \u0418 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 Pg \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0430\u043d\u044b.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0451\u0442\u0435\u0441\u044c \u0441 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u0440\u0435\u0448\u0438\u0442\u044c \u0435\u0451 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u044c\u0442\u0435 statistics target. \u042d\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 analyze \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0443\u0441\u0435\u0440\u0434\u043d\u0435\u0435 \u0438 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0442\u0440\u043e\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0448\u0430\u043d\u0441\u044b, \u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0441\u044f, \u0441\u0442\u0430\u043d\u0443\u0442 \u0435\u0449\u0451 \u043c\u0435\u043d\u044c\u0448\u0435.<\/p>\n<p>  \u041d\u043e \u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 statistics target \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, ANALYZE \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u043d \u043d\u0430\u0441 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u043e\u043b\u043d\u0443\u0435\u0442 (\u043e\u0431\u044b\u0447\u043d\u043e). \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 pg_statistic, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c Pg. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0431\u044b \u043d\u0438 \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c default_statistics_target \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0432 10,000, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044f \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0442\u0430\u043a\u0438\u043c \u0432\u044b\u0441\u043e\u043a\u0438\u043c.<\/p>\n<p>  \u0422\u0435\u043a\u0443\u0449\u0438\u0435 100 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 8.4. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u044b\u043b\u043e 10, \u0438 \u043d\u0430 irc \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438\u0441\u044c \u0441\u043e\u0432\u0435\u0442\u044b \u0435\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 100 \u0432\u0441\u0451 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u043e \u0447\u0435\u043c \u043c\u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0445\u043e\u0442\u044c \u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u0431\u044a\u044f\u0441\u043d\u044e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u043d\u0435 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0431 \u044d\u0442\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c: \u044f \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u044c. \u0422\u0430\u043a \u0447\u0442\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435: \u044d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043c\u043e\u0436\u043d\u043e, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0437\u0430\u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u0441\u043b\u043e\u043c\u0430\u043d\u043e. \u0418 \u0434\u0430, \u044f \u0437\u043d\u0430\u044e, \u0447\u0442\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c. \u041d\u043e \u044d\u0442\u043e \u00ab\u0438\u043d\u043e\u0433\u0434\u0430\u00bb \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u0440\u0435\u0434\u043a\u043e.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u044f \u0432\u0430\u0441 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u043b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0412 postgresql.conf \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a:<\/p>\n<pre><code class=\"sql\">enable_bitmapscan = on enable_hashagg = on enable_hashjoin = on enable_indexscan = on enable_indexonlyscan = on enable_material = on enable_mergejoin = on enable_nestloop = on enable_seqscan = on enable_sort = on enable_tidscan = on <\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 enable_seqscan \u043d\u0430 false (\u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b SET \u0432 \u0441\u0435\u0441\u0441\u0438\u0438 SQL, \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c postgresql.conf) \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e, \u0434\u0430\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0410, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u043d\u043e\u0433\u0434\u0430 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432), \u044d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442 \u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b.<\/p>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440. \u0412 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u00aball_the_same = 123\u00bb \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u0430\u0442\u0440\u0430\u0442:<\/p>\n<pre><code class=\"sql\">explain select * from test where all_the_same = 123;                          QUERY PLAN                          ------------------------------------------------------------  Seq Scan on test  (cost=0.00..1693.00 rows=100000 width=8)    Filter: (all_the_same = 123) (2 rows) <\/code><\/pre>\n<p>  \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043c seq scan:<\/p>\n<pre><code class=\"sql\">set enable_seqscan = false; SET explain select * from test where all_the_same = 123;                               QUERY PLAN                                -----------------------------------------------------------------------  Index Scan using i1 on test  (cost=0.29..3300.29 rows=100000 width=8)    Index Cond: (all_the_same = 123) (2 rows) <\/code><\/pre>\n<p>  \u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u0446\u0435\u043d\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e index scan ~ \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0432\u044b\u0448\u0435 (3300.29 \u043f\u0440\u043e\u0442\u0438\u0432 1693).<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u044f \u0443\u0434\u0430\u043b\u044e i1 \u0438\u043d\u0434\u0435\u043a\u0441:<\/p>\n<pre><code class=\"sql\">drop index i1; DROP INDEX set enable_seqscan = false; SET explain select * from test where all_the_same = 123;                                  QUERY PLAN                                   -----------------------------------------------------------------------------  Seq Scan on test  (cost=10000000000.00..10000001693.00 rows=100000 width=8)    Filter: (all_the_same = 123) (2 rows) <\/code><\/pre>\n<p>  \u0418 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u0440\u043e\u043c\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435\u0442 (\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 index scan \u043f\u043e i2, \u0445\u043e\u0442\u044f \u0443 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435), \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u0432\u0437\u043b\u0435\u0442\u0435\u043b\u0438 \u0434\u043e 10,000,000,000 \u2014 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e enable_* = false \u0438 \u0434\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0432\u0441\u044e \u0441\u0435\u0440\u0438\u044e, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0445\u0432\u0430\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u0435\u0435, \u2014 \u043f\u043e\u0447\u0435\u043c\u0443.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/282011\/\"> https:\/\/habrahabr.ru\/post\/282011\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <i>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043a PG Day\u201916 \u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 PostgreSQL.<\/i><\/p>\n<p>  \u0412 <a href=\"https:\/\/habrahabr.ru\/post\/275851\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/276973\/\">\u043f\u043e\u0441\u0442\u0430\u0445<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/279255\/\">\u044d\u0442\u043e\u0439<\/a> <a href=\"https:\/\/habrahabr.ru\/post\/281036\/\">\u0441\u0435\u0440\u0438\u0438<\/a> \u044f \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 EXPLAIN \u0438 \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 (\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\/\u0443\u0437\u0435\u043b).<\/p>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u041f\u043e\u0441\u0442\u0433\u0440\u0435\u0441 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u00ab\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044e X\u00bb, \u0430 \u043d\u0435 \u00ab\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044e Y\u00bb.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/432\/20b\/3dc\/43220b3dc23746abb0b2c49999a700dc.jpg\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-278655","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=278655"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278655\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=278655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=278655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=278655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}