{"id":287111,"date":"2017-05-31T08:55:04","date_gmt":"2017-05-31T04:55:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287111"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287111","title":{"rendered":"Postgres \u0438 \u041f\u0443\u0441\u0442\u043e\u0442\u0430"},"content":{"rendered":"<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043d\u0430\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c Postgresql, \u043f\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u043c\u043d\u0435 \u0437\u0430\u0431\u0430\u0432\u043d\u043e\u0439.<br \/>  \u0414\u043b\u044f \u043a\u043e\u0433\u043e &quot;\u0431\u043e\u044f\u043d&quot; \u2014 \u0440\u0435\u0441\u043f\u0435\u043a\u0442 \u0432\u0430\u043c, \u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0441 Postgres \u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043d\u0430\u0442\u044b\u043a\u0430\u043b\u0441\u044f \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443.<\/p>\n<p>  <\/p>\n<p><code>select;<\/code> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443.<br \/>  \u041d\u043e \u0443 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u0442 \u043f\u043e\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select; -- (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select null;  ?column?  ----------  (1 row) =&gt; select null where 0=1;  ?column?  ---------- (0 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e &quot;\u043f\u0443\u0441\u0442\u043e\u0433\u043e&quot; \u0437\u0430\u043f\u0440\u043e\u0441\u0430? \u0422\u0430\u0431\u043b\u0438\u0446\u0443 \u0431\u0435\u0437 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u0430 \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; create table t as select; SELECT 1 =&gt; \\d+ t                           Table &quot;t&quot;  Column | Type | Modifiers | Storage | Stats target | Description  --------+------+-----------+---------+--------------+------------- =&gt; select * from t; -- (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0432 \u043d\u0435\u0451 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c?<br \/>  \u041b\u0435\u0433\u043a\u043e:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; insert into t select; INSERT 0 1 =&gt; insert into t select; INSERT 0 1 =&gt; select * from t; -- (3 rows) =&gt; select count(*) from t;  count  -------      3<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0429\u0415!<\/p>\n<p>  <\/p>\n<pre><code>=&gt; insert into t select from generate_series(1,1000000); INSERT 0 1000000<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 Postgresql \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443?<\/p>\n<p>  <\/p>\n<pre><code>=&gt; explain analyze select * from t;                                                  QUERY PLAN                                                  ------------------------------------------------------------------------------------------------------------  Seq Scan on t  (cost=0.00..13438.67 rows=1000167 width=0) (actual time=0.018..96.389 rows=1000003 loops=1)  Planning time: 0.024 ms  Execution time: 134.654 ms (3 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430, \u0447\u0435\u0441\u0442\u043d\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u0442. \u0411\u043e\u043b\u044c\u0448\u0435 100 ms \u2014 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0435\u0431\u0435 \u0437\u0430\u043c\u0435\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<br \/>  \u041d\u0443 \u0438 \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u043f\u043e \u0447\u0435\u0441\u0442\u043d\u043e\u043c\u0443, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u0442\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430\u0448\u0430 \u0441\u0443\u043f\u0435\u0440-\u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select pg_size_pretty(pg_total_relation_size('t'));  pg_size_pretty  ----------------  27 MB (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0435\u0441\u0442\u044c, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435, \u0432 \u0431\u043b\u043e\u043a\u0430\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0443 \u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043f\u043e\u043b\u0435\u0439 \u2014 \u0431\u044b\u0432\u0430\u0435\u0442, \u0434\u0435\u043b\u043e \u0436\u0438\u0442\u0435\u0439\u0441\u043a\u043e\u0435!<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select t.xmin, t.ctid from t limit 10;   xmin   |  ctid   ---------+--------  1029645 | (0,1)  1029647 | (0,2)  1029648 | (0,3)  1029649 | (0,4)  1029649 | (0,5)  1029649 | (0,6)  1029649 | (0,7)  1029649 | (0,8)  1029649 | (0,9)  1029649 | (0,10) (10 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042f \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b, \u0437\u0430\u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430. \u041d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0435\u0441\u0442\u044c, \u0438 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e!<\/p>\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\/329856\/\"> https:\/\/habrahabr.ru\/post\/329856\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0422\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043d\u0430\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c Postgresql, \u043f\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u043c\u043d\u0435 \u0437\u0430\u0431\u0430\u0432\u043d\u043e\u0439.<br \/>  \u0414\u043b\u044f \u043a\u043e\u0433\u043e &quot;\u0431\u043e\u044f\u043d&quot; \u2014 \u0440\u0435\u0441\u043f\u0435\u043a\u0442 \u0432\u0430\u043c, \u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0441 Postgres \u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043d\u0430\u0442\u044b\u043a\u0430\u043b\u0441\u044f \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443.<\/p>\n<p>  <\/p>\n<p><code>select;<\/code> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443.<br \/>  \u041d\u043e \u0443 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u0442 \u043f\u043e\u043b\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select; -- (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code>=&gt; select null;  ?column?  ----------  (1 row) =&gt; select null where 0=1;  ?column?  ---------- (0 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e &quot;\u043f\u0443\u0441\u0442\u043e\u0433\u043e&quot; \u0437\u0430\u043f\u0440\u043e\u0441\u0430? \u0422\u0430\u0431\u043b\u0438\u0446\u0443 \u0431\u0435\u0437 \u043f\u043e\u043b\u0435\u0439.<\/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-287111","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287111","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=287111"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287111\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}