{"id":234909,"date":"2014-08-29T18:45:12","date_gmt":"2014-08-29T14:45:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=234909"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=234909","title":{"rendered":"<span class=\"post_title\">PostgreSQL 9.4 \u0427\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e?<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e4d\/bbf\/55f\/e4dbbf55fe4b41a6be0500fe74f738f1.png\"\/><\/p>\n<p>  \u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! \u041d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438 \u0440\u0435\u043b\u0438\u0437 PostgreSQL 9.4 \u0438 \u043d\u0435\u043b\u0438\u0448\u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432\u0430\u043c, \u043f\u0440\u0438\u0432\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b (\u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, \u043a\u0430\u0441\u0430\u0435\u043c\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438):<\/p>\n<ul>\n<li><a href=\"#autoupdatable_views\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/a><\/li>\n<li><a href=\"#materialized_views\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/a><\/li>\n<li><a href=\"#alter_system\">\u043a\u043e\u043c\u0430\u043d\u0434\u0430 ALTER SYSTEM \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/a><\/li>\n<li><a href=\"#with_ordinality\">\u043e\u043f\u0446\u0438\u044f WITH ORDINALITY \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a<\/a><\/li>\n<li><a href=\"#aggregate_funcs\">\u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/li>\n<li><a href=\"#gin_gist\">\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 GIN \u0438 GiST<\/a><\/li>\n<li><a href=\"#explain\">\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b EXPLAIN<\/a><\/li>\n<li><a href=\"#prewarm\">\u0440\u0430\u0437\u043e\u0433\u0440\u0435\u0432 \u043a\u044d\u0448\u0430<\/a><\/li>\n<li><a href=\"#foreign_table_triggers\">\u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446<\/a><\/li>\n<li><a href=\"#json\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f json \u0438 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 jsonb<\/a><\/li>\n<\/ul>\n<p>  <a name=\"habracut\"><\/a><br \/>  <a name=\"autoupdatable_views\"><\/a>  <\/p>\n<h5><b>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/b><\/h5>\n<p>  \u0410\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (<i>autoupdatable views<\/i>) \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <b>DML<\/b>-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439:  <\/p>\n<ul>\n<li>\u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435) \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 <b>FROM<\/b><\/li>\n<li>\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 <b>WITH<\/b>, <b>DISTINCT<\/b>, <b>GROUP BY<\/b>, <b>HAVING<\/b>, <b>LIMIT<\/b> \u0438 <b>OFFSET<\/b><\/li>\n<li>\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438 <b>UNION<\/b>, <b>INTERSECT<\/b> \u0438 <b>EXCEPT<\/b><\/li>\n<li>\u043a \u043f\u043e\u043b\u044f\u043c \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/li>\n<\/ul>\n<p>  \u042d\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 PostgreSQL 9.3. \u0412 \u0432\u0435\u0440\u0441\u0438\u0438 9.4 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a \u043d\u0438\u043c. \u041e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445 \u0441\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0439, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b (\u0432 9.3, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u043f\u043e\u043b\u044f, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u043c). \u0412 9.4 \u0436\u0435, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438. \u041f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043a\u043d\u0438\u0433 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u043e \u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"sql\">CREATE TABLE book ( \tid serial NOT NULL, \tname text NOT NULL, \tauthor text NOT NULL, \tyear integer NOT NULL,  \tCONSTRAINT pk_book_id PRIMARY KEY ( id ), \tCONSTRAINT uk_book UNIQUE ( name, author ) );  INSERT INTO book ( name, author, year ) VALUES ( '\u041a\u043d\u0438\u0433\u0430 \u21161', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418. \u0418.', 2010 ), ( '\u041a\u043d\u0438\u0433\u0430 \u21162', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418. \u0418.', 2011 ), ( '\u041a\u043d\u0438\u0433\u0430 \u21163', '\u041f\u0435\u0442\u0440\u043e\u0432 \u041f. \u041f.', 2012 );  CREATE OR REPLACE VIEW vw_book AS SELECT b.id, \tb.name, \tb.author, \tb.year, \t( b.year &gt;= extract ( year FROM current_date ) - 2 ) AS is_new FROM book b; <\/code><\/pre>\n<p>  \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435:  <\/p>\n<pre><code class=\"sql\">-- \u0432\u0441\u0451 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043f\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f UPDATE vw_book SET name = '\u041a\u043d\u0438\u0433\u0430 \u211610' WHERE name = '\u041a\u043d\u0438\u0433\u0430 \u21161';  -- \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e\u043b\u0435 is_new \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u043e\u0435 UPDATE vw_book SET is_new = false WHERE name = '\u041a\u043d\u0438\u0433\u0430 \u21163';  -- \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c SELECT * FROM vw_book b;  -- \u0432\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c SELECT c.column_name, \t( is_updatable = 'YES' ) AS is_updatable FROM information_schema.columns c WHERE c.table_name = 'vw_book' ORDER BY ordinal_position; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441\u0442\u0430\u043b\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043e\u043f\u0446\u0438\u044f <b>WITH CHECK OPTION<\/b>. \u0421\u043c\u044b\u0441\u043b \u0435\u0451 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u043f\u0440\u0438 <b>INSERT<\/b> \u0438 <b>UPDATE<\/b> \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c <b>WHERE<\/b> \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0440\u044b\u0435 \u043a\u043d\u0438\u0433\u0438 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043a\u043d\u0438\u0433 \u0447\u0435\u0440\u0435\u0437 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"sql\">-- \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0435 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 CREATE OR REPLACE VIEW vw_book_archive AS SELECT b.id, \tb.name, \tb.author, \tb.year FROM vw_book b WHERE b.is_new = false WITH CHECK OPTION;  -- \u043e\u0448\u0438\u0431\u043a\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f year \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f INSERT INTO vw_book_archive ( name, author, year ) VALUES ( '\u041a\u043d\u0438\u0433\u0430 \u2116100', '\u0421\u0438\u0434\u043e\u0440\u043e\u0432 \u0421. \u0421.', 2014 );  -- \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435\u0442 INSERT INTO vw_book_archive ( name, author, year ) VALUES ( '\u041a\u043d\u0438\u0433\u0430 \u2116100', '\u0421\u0438\u0434\u043e\u0440\u043e\u0432 \u0421. \u0421.', 2010 ); <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043e\u0431\u044c\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 <i>security_barrier<\/i>, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u044e\u0442 \u0431\u044b\u0442\u044c \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <i>security_barrier<\/i> \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043d\u0438\u0433\u0438 \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"sql\">-- \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 DELETE FROM book;  INSERT INTO book ( id, name, author, year ) VALUES ( 1, '\u041a\u043d\u0438\u0433\u0430 \u21161', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418. \u0418.', 2010 ), ( 2, '\u041a\u043d\u0438\u0433\u0430 \u21162', '\u0418\u0432\u0430\u043d\u043e\u0432 \u0418. \u0418.', 2011 ), ( 3, '\u041a\u043d\u0438\u0433\u0430 \u21163', '\u041f\u0435\u0442\u0440\u043e\u0432 \u041f. \u041f.', 2012 );  -- \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f ALTER TABLE book ADD COLUMN promotion_code text;  -- \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 UPDATE book SET promotion_code = 'CODE_' || id; <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u044e\u0449\u0435\u0435 \u043a\u043d\u0438\u0433\u0438 (\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0432 \u043d\u0435\u043a\u0443\u044e \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043d\u0438\u0433\u0443) \u0438 \u0438\u0445 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043a\u043e\u0434\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u044b\u0432\u043e\u0434\u044f\u0449\u0443\u044e \u0447\u0435\u0440\u0435\u0437 RAISE NOTICE \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043d\u0438\u0433\u0438 \u0438 \u0435\u0451 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"sql\">CREATE OR REPLACE VIEW vw_book_list AS SELECT b.* FROM book b WHERE b.name != '\u041a\u043d\u0438\u0433\u0430 \u21161';  CREATE OR REPLACE FUNCTION fn_book_promotion_code ( p_name text, p_code text ) RETURNS boolean AS $BODY$ BEGIN \tRAISE NOTICE 'Book &quot;%&quot; has code &quot;%&quot;', p_name, p_code; \tRETURN true; END $BODY$ LANGUAGE plpgsql COST 100; <\/code><\/pre>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u0432\u044b\u0437\u0432\u0430\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <i>fn_book_promotion_code<\/i> \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043a\u043d\u0438\u0433\u0438) \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430:  <\/p>\n<pre><code class=\"sql\">SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code );  -- \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c: -- \u041a\u043d\u0438\u0433\u0430 \u21162 CODE_2 -- \u041a\u043d\u0438\u0433\u0430 \u21163 CODE_3  -- \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u043e\u0436\u0435: -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21162&quot; has code &quot;CODE_2&quot; -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21163&quot; has code &quot;CODE_3&quot;  EXPLAIN ANALYZE SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code ); --  Seq Scan on book b  (cost=0.00..1.79 rows=1 width=23) (actual time=0.185..0.217 rows=2 loops=1)   Filter: ((name &lt;&gt; '\u041a\u043d\u0438\u0433\u0430 \u21161'::text) AND fn_book_promotion_code(name, promotion_code))   Rows Removed by Filter: 1 Planning time: 0.064 ms Execution time: 0.229 ms <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u0444\u0438\u043b\u044c\u0442\u0440\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u043a\u043d\u0438\u0433\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <i>fn_book_promotion_code<\/i>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u043f\u043e\u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043f\u043b\u0430\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430:  <\/p>\n<pre><code class=\"sql\">CREATE OR REPLACE FUNCTION fn_book_promotion_code ( p_name text, p_code text ) RETURNS boolean AS $BODY$ BEGIN \tRAISE NOTICE 'Book &quot;%&quot; has code &quot;%&quot;', p_name, p_code; \tRETURN true; END $BODY$ LANGUAGE plpgsql COST 0.01;  SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code );  -- \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c: -- \u041a\u043d\u0438\u0433\u0430 \u21162 CODE_2 -- \u041a\u043d\u0438\u0433\u0430 \u21163 CODE_3  -- \u0430 \u0432\u043e\u0442 \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c: -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21161&quot; has code &quot;CODE_1&quot; -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21162&quot; has code &quot;CODE_2&quot; -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21163&quot; has code &quot;CODE_3&quot;  EXPLAIN ANALYZE SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code ); -- Seq Scan on book b  (cost=0.00..1.04 rows=1 width=23) (actual time=0.215..0.240 rows=2 loops=1)   Filter: (fn_book_promotion_code(name, promotion_code) AND (name &lt;&gt; '\u041a\u043d\u0438\u0433\u0430 \u21161'::text))   Rows Removed by Filter: 1 Planning time: 0.064 ms Execution time: 0.254 ms <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u0438\u0437\u0435\u0440\u043d\u0430\u044f, \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441\u043f\u0435\u0440\u0432\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0438\u043c\u044f \u043a\u043d\u0438\u0433\u0438. \u0427\u0442\u043e, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438. \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 vw_book_list \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 <i>security_barrier<\/i>:  <\/p>\n<pre><code class=\"sql\">CREATE OR REPLACE VIEW vw_book_list WITH ( security_barrier = true ) AS SELECT b.* FROM book b WHERE b.name != '\u041a\u043d\u0438\u0433\u0430 \u21161';  SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code );  -- \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430: -- \u041a\u043d\u0438\u0433\u0430 \u21162 CODE_2 -- \u041a\u043d\u0438\u0433\u0430 \u21163 CODE_3  -- \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21161&quot; has code &quot;CODE_1&quot; -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21162&quot; has code &quot;CODE_2&quot; -- NOTICE:  Book &quot;\u041a\u043d\u0438\u0433\u0430 \u21163&quot; has code &quot;CODE_3&quot;  EXPLAIN ANALYZE SELECT name, promotion_code FROM vw_book_list l WHERE fn_book_promotion_code ( l.name, l.promotion_code ); --  Subquery Scan on l  (cost=0.00..1.06 rows=1 width=23) (actual time=0.078..0.106 rows=2 loops=1)   Filter: fn_book_promotion_code(l.name, l.promotion_code)   -&gt;  Seq Scan on book b  (cost=0.00..1.04 rows=2 width=52) (actual time=0.009..0.010 rows=2 loops=1)         Filter: (name &lt;&gt; '\u041a\u043d\u0438\u0433\u0430 \u21161'::text)         Rows Removed by Filter: 1 Planning time: 0.069 ms Execution time: 0.122 ms <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0432\u044b\u0434\u0435\u043b\u0438\u043b \u0444\u0438\u043b\u044c\u0442\u0440 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <i>vw_book_list<\/i> \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u043c:  <\/p>\n<pre><code class=\"sql\">UPDATE vw_book_list SET promotion_code = 'CODE_555' WHERE name = '\u041a\u043d\u0438\u0433\u0430 \u21162'; <\/code><\/pre>\n<p>  <a name=\"materialized_views\"><\/a>  <\/p>\n<h5><b>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/b><\/h5>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0432 PostgreSQL 9.3, \u0431\u044b\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u044d\u043a\u0441\u043a\u043b\u044e\u0437\u0438\u0432\u043d\u0430\u044f (<b>ACCESS EXCLUSIVE<\/b>) \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0434\u0435\u043b\u0430\u044e\u0449\u0430\u044f \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e. \u0412 9.4 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b <b>REFRESH MATERIALIZED VIEW<\/b> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u043f\u0446\u0438\u044f <b>CONCURRENTLY<\/b> \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 <b>EXCLUSIVE<\/b>, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0443\u044e \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438 <b>ACCESS SHARE<\/b>, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 <b>SELECT<\/b>. \u0417\u0430 \u043a\u0430\u0434\u0440\u043e\u043c, \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0438, \u043f\u0440\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u0445, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <b>INSERT<\/b> \u0438 <b>DELETE<\/b>. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <b>UNIQUE INDEX<\/b> \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u043e\u043b\u044f\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438:  <\/p>\n<pre><code class=\"sql\">-- \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 CREATE TABLE author (     id serial NOT NULL,     first_name text NOT NULL,     last_name text NOT NULL,      CONSTRAINT pk_author_id PRIMARY KEY ( id ),     CONSTRAINT uk_author_name UNIQUE ( first_name, last_name ) );  -- \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 CREATE TABLE publication (     id serial NOT NULL,     author_id integer NOT NULL,     name text NOT NULL,      CONSTRAINT pk_publication_id PRIMARY KEY ( id ),     CONSTRAINT fk_publication_author_id FOREIGN KEY ( author_id ) REFERENCES author ( id ),     CONSTRAINT uk_publication_name UNIQUE ( author_id, name ) );  -- \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438  INSERT INTO author ( first_name, last_name ) VALUES ( '\u0418\u0432\u0430\u043d',  '\u0418\u0432\u0430\u043d\u043e\u0432' ); -- \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d id = 1 INSERT INTO author ( first_name, last_name ) VALUES ( '\u041f\u0451\u0442\u0440', '\u041f\u0435\u0442\u0440\u043e\u0432' ); -- \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d id = 2  INSERT INTO publication ( author_id, name ) VALUES ( 1, '\u041f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u2116' || generate_series ( 1, 1000000 ) || ')' );  INSERT INTO publication ( author_id, name ) VALUES ( 2, '\u0414\u0440\u0443\u0433\u0430\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f' ), ( 2, '\u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f' );  \u2013- \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0438\u043d\u0434\u0435\u043a\u0441 CREATE MATERIALIZED VIEW mvw_publication AS SELECT p.id, a.first_name || ' ' || a.last_name AS author_name, p.name FROM  publication p INNER JOIN author a ON a.id = p.author_id;  CREATE UNIQUE INDEX idx_mvw_publication_id ON mvw_ publication ( id );  -- \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f REFRESH MATERIALIZED VIEW CONCURRENTLY mvw_publication;  \u2013- \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f...  \u2013- \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438) SELECT * FROM mvw_publication;  \u2013- \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a SELECT l.mode FROM pg_locks l INNER JOIN pg_class c ON c.oid = l.relation WHERE \u0441.relname = 'mvw_publication'; <\/code><\/pre>\n<p>  <a name=\"alter_system\"><\/a>  <\/p>\n<h5><b>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 ALTER SYSTEM \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/b><\/h5>\n<p>  \u042d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 SQL-\u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434 <b>SET<\/b> \u0438 <i>set_config<\/i>, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0441\u0441\u0438\u044e (\u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e), \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u043c. \u041f\u043e \u0444\u0430\u043a\u0442\u0443, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b $PGDATA\/postgresql.auto.conf, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c (\u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0438\u043b\u0438 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 <b>SIGHUP<\/b>) \u043f\u043e\u0441\u043b\u0435 \u0447\u0442\u0435\u043d\u0438\u044f postgresql.conf. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:  <\/p>\n<pre><code class=\"sql\">-- \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 ALTER SYSTEM SET log_min_duration_statement = '1min';  -- \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 ALTER SYSTEM SET log_min_duration_statement TO '2min';    -- \u0441\u0431\u0440\u043e\u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 ALTER SYSTEM SET log_min_duration_statement TO DEFAULT; <\/code><\/pre>\n<p>  <a name=\"with_ordinality\"><\/a>  <\/p>\n<h5><b>\u041e\u043f\u0446\u0438\u044f WITH ORDINALITY \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a<\/b><\/h5>\n<p>  \u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <i>unnest<\/i> (\u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a), \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u043e\u043f\u0446\u0438\u044f <b>WITH ORDINALITY<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0440\u043e\u043a\u0438. \u0422\u0430\u043a\u0436\u0435, \u0432 unnest \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u043c:  <\/p>\n<pre><code class=\"sql\">SELECT * FROM unnest \t( \t\tARRAY['cat', 'dog', 'mouse'], \t\tARRAY['Tom', 'Jack', 'Lili'] \t) WITH ORDINALITY \tAS t ( cat, dog, mouse );  -- \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: -- cat Tom 1 -- dog Jack 2 -- mouse Lili 3  -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 \u043e\u043a\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 SELECT *, row_number() OVER () AS i FROM unnest \t( \t\tARRAY['cat', 'dog', 'mouse'], \t\tARRAY['Tom', 'Jack', 'Lili'] \t) \tAS t ( cat, dog, mouse ); <\/code><\/pre>\n<p>  <a name=\"aggregate_funcs\"><\/a>  <\/p>\n<h5><b>\u041d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/b><\/h5>\n<p>  \u041a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c-\u0430\u0433\u0440\u0435\u0433\u0430\u0442\u0430\u043c (<i>sum<\/i>, <i>avg<\/i>, <i>corr<\/i> \u0438 \u0442. \u0434.), \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0438 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u044f\u0434\u043e\u0432:  <\/p>\n<pre><code class=\"sql\">-- \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 CREATE TABLE salary AS SELECT ( random ( ) * 100 + 2000 )::int AS value FROM generate_series ( 1, 100 );  -- \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 SELECT mode() WITHIN GROUP ( ORDER BY value DESC ) FROM salary;  -- \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0435 \u0438\u043b\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0444\u0440\u0430\u043a\u0446\u0438\u0438 SELECT percentile_disc ( 0.5 ) WITHIN GROUP ( ORDER BY value ) FROM salary;   -- \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u0444\u0440\u0430\u043a\u0446\u0438\u0438 (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0435\u0439 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438) SELECT percentile_cont ( 0.5 ) WITHIN GROUP ( ORDER BY value ) FROM salary;   -- \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u043d\u0433 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u044f\u0434\u0430 (\u043e\u0442 1 \/ n \u0434\u043e 1) SELECT s.value, cume_dist ( 2026 ) WITHIN GROUP ( ORDER BY value ) FROM salary s GROUP BY s.value; <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043e\u043f\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"sql\">-- \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0437\u0430\u0440\u043f\u043b\u0430\u0442\u0430, \u0441\u0440\u0435\u0434\u0438 \u0437\u0430\u0440\u043f\u043b\u0430\u0442 \u0432\u044b\u0448\u0435 2050 SELECT avg ( s.value ) FILTER ( WHERE s.value &gt;= 2050 ) FROM salary s;  -- \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 CASE WHEN \u2026 SELECT avg ( CASE WHEN s.value &gt;= 2050 THEN s.value ELSE NULL END ) FROM salary s; <\/code><\/pre>\n<p>  <a name=\"gin_gist\"><\/a>  <\/p>\n<h5><b>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 GIN \u0438 GiST<\/b><\/h5>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441\u044b <b>GIN<\/b> (\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430. \u0414\u043b\u044f <b>GiST<\/b> \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 <b>inet<\/b> \u0438 <b>cidr<\/b>:  <\/p>\n<pre><code class=\"sql\">-- \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 CREATE TABLE machine ( \tip cidr );  INSERT INTO machine ( ip ) VALUES ( '192.168.1.1'::cidr ), ( '192.168.1.10'::cidr ), ( '192.168.2.11'::cidr );  -- \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441    CREATE INDEX idx_machine_ip ON machine USING GiST ( ip inet_ops );  -- \u0430\u0434\u0440\u0435\u0441\u0430 \u0441 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 192.168.1.0\/24 SELECT * FROM machine WHERE ip && '192.168.1.0\/24'::cidr; <\/code><\/pre>\n<p>  <a name=\"explain\"><\/a>  <\/p>\n<h5><b>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b EXPLAIN<\/b><\/h5>\n<p>  \u0412 \u0432\u044b\u0432\u043e\u0434\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <b>EXPLAIN<\/b> \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (<i>planning time<\/i>):  <\/p>\n<pre><code class=\"sql\">EXPLAIN ANALYZE SELECT s.value, count ( * ) FROM salary s GROUP BY s.value HAVING count ( * ) &gt;= 2; -- HashAggregate  (cost=2.75..3.60 rows=68 width=4) (actual time=0.045..0.053 rows=26 loops=1)   Group Key: value   Filter: (count(*) &gt;= 2)   Rows Removed by Filter: 42   -&gt;  Seq Scan on salary s  (cost=0.00..2.00 rows=100 width=4) (actual time=0.007..0.015 rows=100 loops=1) Planning time: 0.042 ms Execution time: 0.082 ms <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <i>bitmap heap scan<\/i>, \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u043e\u043a\u043e\u0432 \u0441\u043e\u0432\u043f\u0430\u043b\u043e (<i>exact<\/i>), \u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 (<i>lossy<\/i>):  <\/p>\n<pre><code class=\"sql\">-- \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 INSERT INTO salary ( value ) SELECT ( random ( ) * 10000 + 1000 )::int AS value FROM generate_series ( 1, 1000000 );  CREATE INDEX idx_salary_value ON salary ( value );  SET work_mem = '64kB';  EXPLAIN ANALYZE SELECT * FROM salary s WHERE s.value BETWEEN 2010 AND 2020; --  Bitmap Heap Scan on salary s  (cost=28.83..2739.72 rows=1210 width=4) (actual time=0.370..17.824 rows=1030 loops=1)   Recheck Cond: ((value &gt;= 2010) AND (value &lt;= 2020))   Rows Removed by Index Recheck: 96457   Heap Blocks: exact=486 lossy=429   -&gt;  Bitmap Index Scan on idx_salary_value  (cost=0.00..28.53 rows=1210 width=0) (actual time=0.286..0.286 rows=1030 loops=1)         Index Cond: ((value &gt;= 2010) AND (value &lt;= 2020)) Planning time: 0.098 ms Execution time: 17.920 ms  SET work_mem = '32MB';  EXPLAIN ANALYZE SELECT * FROM salary s WHERE s.value BETWEEN 2010 AND 2020; --  Bitmap Heap Scan on salary s  (cost=28.83..2739.72 rows=1210 width=4) (actual time=0.283..1.214 rows=1030 loops=1)   Recheck Cond: ((value &gt;= 2010) AND (value &lt;= 2020))   Heap Blocks: exact=915   -&gt;  Bitmap Index Scan on idx_salary_value  (cost=0.00..28.53 rows=1210 width=0) (actual time=0.157..0.157 rows=1030 loops=1)         Index Cond: ((value &gt;= 2010) AND (value &lt;= 2020)) Planning time: 0.076 ms Execution time: 1.269 ms <\/code><\/pre>\n<p>  <a name=\"prewarm\"><\/a>  <\/p>\n<h5><b>\u0420\u0430\u0437\u043e\u0433\u0440\u0435\u0432 \u043a\u044d\u0448\u0430<\/b><\/h5>\n<p>  \u0412 \u043d\u043e\u0432\u043e\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0438 <b>pg_prewarm<\/b> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043e\u0434\u043d\u043e\u0438\u043c\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0444\u043e\u0440\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u044d\u0448 (\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u041e\u0421 \u0438\u043b\u0438 PostgreSQL). \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:  <\/p>\n<pre><code class=\"sql\">CREATE EXTENSION pg_prewarm;  CREATE TABLE big AS SELECT array_to_string ( array_agg ( t.x ), '' ) \t|| '#' || generate_series ( 1, 10000 ) AS value FROM ( SELECT 'a' || generate_series ( 1, 1000 ) AS x ) t;  -- \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 ALTER SYSTEM SET shared_buffers = '256MB'; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440 PostgreSQL, \u0441\u0431\u0440\u043e\u0441\u0438\u043c \u043a\u044d\u0448\u0438 \u041e\u0421 \u043d\u0430 \u0434\u0438\u0441\u043a \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043d\u043e\u0432\u0430 (\u0432 \u0432\u0430\u0448\u0435\u0439 \u041e\u0421 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u044b\u0435):  <\/p>\n<pre><code class=\"bash\">\/etc\/init.d\/postgresql-9.4 stop sync \/etc\/init.d\/postgresql-9.4 start <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043a \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u044f, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435:  <\/p>\n<pre><code class=\"sql\">-- \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 EXPLAIN ( ANALYZE, BUFFERS ) SELECT * FROM big; -- Seq Scan on big  (cost=0.00..76047.00 rows=5000000 width=8) (actual time=0.013..448.978 rows=5000000 loops=1)   Buffers: shared read=26047 Planning time: 0.081 ms Execution time: 689.083 ms  -- \u0432\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 EXPLAIN ( ANALYZE, BUFFERS ) SELECT * FROM big; -- Seq Scan on big  (cost=0.00..76047.00 rows=5000000 width=8) (actual time=0.044..449.973 rows=5000000 loops=1)   Buffers: shared hit=32 read=26015 Planning time: 0.027 ms Execution time: 692.045 ms  -- \u0442\u0440\u0435\u0442\u044c\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 EXPLAIN ( ANALYZE, BUFFERS ) SELECT * FROM big; -- Seq Scan on big  (cost=0.00..76047.00 rows=5000000 width=8) (actual time=0.044..449.973 rows=5000000 loops=1)   Buffers: shared hit=32 read=26015 Planning time: 0.027 ms Execution time: 692.045 ms <\/code><\/pre>\n<p>  \u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043a\u044d\u0448\u0435 \u0435\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442, \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0441 \u0434\u0438\u0441\u043a\u0430 (<i>shared read<\/i>), \u043d\u043e \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043a\u044d\u0448 \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f (<i>shared hit<\/i>).<\/p>\n<p>  \u0421\u043d\u043e\u0432\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440 PostgreSQL, \u0441\u0431\u0440\u043e\u0441\u0438\u043c \u043a\u044d\u0448 \u041e\u0421 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440. \u0418 \u043e\u043f\u044f\u0442\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <b>EXPLAIN<\/b>, \u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u044d\u0448 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:  <\/p>\n<pre><code class=\"sql\">-- \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043e 26047 \u0431\u043b\u043e\u043a\u043e\u0432 SELECT pg_prewarm ( 'big' );  EXPLAIN ( ANALYZE, BUFFERS ) SELECT * FROM big; -- Seq Scan on big  (cost=0.00..76047.00 rows=5000000 width=8) (actual time=0.007..407.269 rows=5000000 loops=1)   Buffers: shared hit=26047 Planning time: 0.129 ms Execution time: 642.834 ms <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u044d\u0448\u0435.<br \/>  <a name=\"foreign_table_triggers\"><\/a>  <\/p>\n<h5><b>\u0422\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446<\/b><\/h5>\n<p>  \u0412 PostgreSQL 9.3 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <b>postgres_fdw<\/b>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c read\/write \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0411\u0414 \u2014 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c (<i>foreign tables<\/i>). \u0412 9.4 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u043a \u043d\u0438\u043c. <\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u043d\u0435\u0448\u043d\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:  <\/p>\n<pre><code class=\"sql\">-- \u0432 \u0411\u0414 test0 CREATE TABLE city (     country text NOT NULL,     name text NOT NULL,      CONSTRAINT uk_city_name UNIQUE ( country, name ) );  -- \u0432 \u0411\u0414 test1 CREATE EXTENSION postgres_fdw;  -- \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 CREATE SERVER fdb_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS ( host 'localhost', port '5432', dbname 'test0' );  -- \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f CREATE USER MAPPING FOR PUBLIC SERVER fdb_server OPTIONS ( password 'pwd' );  -- \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b CREATE FOREIGN TABLE fdb_city ( country text, name text ) SERVER fdb_server OPTIONS ( table_name 'city' ); <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0440\u0438\u0433\u0433\u0435\u0440, \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u044e\u0449\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0433\u043e\u0440\u043e\u0434\u0430 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c N\/A \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0435\u0433\u043e:  <\/p>\n<pre><code class=\"sql\">-- \u0432 \u0411\u0414 test1 CREATE OR REPLACE FUNCTION tfn_city_change ( ) RETURNS trigger AS $BODY$ BEGIN  \tIF ( NEW.name = 'N\/A' ) THEN \t\tRAISE EXCEPTION 'City with name &quot;N\/A&quot; not allowed'; \tEND IF;  \tRETURN NEW; END $BODY$ LANGUAGE plpgsql VOLATILE;  CREATE TRIGGER tr_city_change BEFORE INSERT ON fdb_city FOR EACH ROW EXECUTE PROCEDURE tfn_city_change ( );  -- \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f INSERT INTO fdb_city ( country, name ) VALUES ( 'USA', 'New York' );  -- \u0430 \u0432\u043e\u0442 \u044d\u0442\u0430 \u043d\u0435\u0442 INSERT INTO fdb_city ( country, name ) VALUES ( 'USA', 'N\/A' ); <\/code><\/pre>\n<p>  \u041d\u043e \u0432 \u0411\u0414 test0 \u044d\u0442\u043e\u0442 \u0442\u0440\u0438\u0433\u0433\u0435\u0440 \u00ab\u043d\u0435 \u0432\u0438\u0434\u0435\u043d\u00bb, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0433\u043e\u0440\u043e\u0434\u043e\u0432:  <\/p>\n<pre><code class=\"sql\">-- \u0432 \u0411\u0414 test0 -- \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f INSERT INTO city ( country, name ) VALUES ( 'Italy', 'N\/A' ); <\/code><\/pre>\n<p>  <a name=\"json\"><\/a>  <\/p>\n<h5><b>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f json \u0438 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 jsonb<\/b><\/h5>\n<p>  \u0411\u0435\u0441\u0441\u043f\u043e\u0440\u043d\u043e, \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f <i>jsonb<\/i> \u0431\u044b\u043b \u0441\u0430\u043c\u044b\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0432 PostgreSQL 9.4. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438, \u043e\u043d \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u043e\u0442 <i>json<\/i>, \u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u0432\u0451\u0440\u043d\u0443\u0442\u043e\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0447\u0442\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0445\u0440\u0430\u043d\u0438\u0442\u044c JSON \u043b\u0443\u0447\u0448\u0435 \u0432 <i>jsonb<\/i>. <\/p>\n<p>  \u0414\u043b\u044f <i>jsonb<\/i> \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b (<b>GIN<\/b>, <b>btree<\/b> \u0438 <b>hash<\/b>). \u0412 <b>GIN<\/b> \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0430:  <\/p>\n<ul>\n<li>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 (jsonb_ops) \u2013 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b @&gt;, ?, ?&#038; \u0438 ?|<\/li>\n<li>jsonb_path_ops \u2013 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 @&gt;<\/li>\n<\/ul>\n<p>  \u0425\u043e\u0442\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <i>jsonb_path_ops<\/i> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043e\u043d \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0435\u043c <i>jsonb_ops<\/i>.<\/p>\n<p>  \u041d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 JSON \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u044f (\u0434\u043b\u044f \u0442\u0438\u043f\u0430 <i>jsonb<\/i>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, jsonb_*):  <\/p>\n<ul>\n<li>json_array_elements_text \u2013 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 JSON \u0432 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0442\u0438\u043f\u043e\u043c text<\/li>\n<li>json_array_elements_text \u2013 \u0441\u0432\u0451\u0440\u0442\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 JSON<\/li>\n<li>json_object \u2013 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 JSON \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 text<\/li>\n<li>json_typeof \u2013 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u0438\u043f\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f JSON<\/li>\n<\/ul>\n<p>  \u0422\u0438\u043f\u044b JSON \u0438 PostgreSQL \u0438\u043c\u0435\u044e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0430 \u0434\u043b\u044f <i>null<\/i> \u043d\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a NULL \u0432 PostgreSQL \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439):  <\/p>\n<table>\n<tr>\n<th>\u0422\u0438\u043f JSON<\/th>\n<th>\u0422\u0438\u043f PostgreSQL<\/th>\n<\/tr>\n<tr>\n<td>string<\/td>\n<td>text<\/td>\n<\/tr>\n<tr>\n<td>number<\/td>\n<td>numeric<\/td>\n<\/tr>\n<tr>\n<td>boolean<\/td>\n<td>boolean<\/td>\n<\/tr>\n<\/table>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 JSON:  <\/p>\n<pre><code class=\"sql\">-- \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u043a\u043d\u0438\u0433 CREATE TABLE book ( \tid serial NOT NULL, \tname text NOT NULL, \tparams jsonb NOT NULL DEFAULT '{}' );  -- \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 INSERT INTO book ( name, params ) SELECT '\u041a\u043d\u0438\u0433\u0430 #' || t.x, \t( '{ &quot;pages&quot;: ' || 500 + ( t.x % 500 ) \t\t|| CASE t.x % 1000 WHEN 0 THEN ', &quot;gold_edition&quot;: true' ELSE '' END \t\t|| ' }' )::jsonb FROM ( SELECT generate_series ( 1, 1000000 ) x ) t;  -- \u0441\u043a\u043e\u043b\u044c\u043a\u043e &quot;\u0437\u043e\u043b\u043e\u0442\u044b\u0445&quot; \u0438\u0437\u0434\u0430\u043d\u0438\u0439 SELECT count ( * ) FROM book WHERE params @&gt; '{ &quot;gold_edition&quot;: true }'::jsonb;  -- \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043b\u0438 \u0432 \u043a\u043d\u0438\u0433\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 SELECT count ( * ) &gt; 0 FROM book WHERE name = '\u041a\u043d\u0438\u0433\u0430 #1' AND \tparams ? 'pages';  -- \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432 \u043a\u043d\u0438\u0433\u0435 SELECT params -&gt; 'pages' FROM book WHERE name = '\u041a\u043d\u0438\u0433\u0430 #11';  -- \u0442\u0438\u043f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 &quot;pages&quot; SELECT jsonb_typeof ( params -&gt; 'pages' ) FROM book WHERE name = '\u041a\u043d\u0438\u0433\u0430 #11';  -- \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 CREATE INDEX idx_book_params ON book USING gin ( params jsonb_path_ops );  <\/code><\/pre>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b @&gt;,? \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b \u0434\u043b\u044f \u0442\u0438\u043f\u0430 <i>jsonb<\/i>. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 <i>jsonb<\/i> \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0442\u044f\u043d\u0435\u0442 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f (\u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u0441\u0430\u0435\u043c\u044b\u0435 SSL, VACUUM \u0438 backgound_workers). \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a changelog-\u0443, \u0437\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439. \u0418 \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e PostgreSQL \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0434\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0442\u0430\u043a \u0438 \u0432 NoSQL \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445. \u041f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0443\u043b\u0443\u0447\u0448\u0430\u044e\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438:  <\/p>\n<ul>\n<li><a href=\"http:\/\/www.postgresql.org\/docs\/9.4\/static\/release-9-4.html\">Release 9.4<\/a><\/li>\n<li><a href=\"http:\/\/www.pgcon.org\/2014\/schedule\/attachments\/318_pgcon-2014-vodka.pdf\">CREATE INDEX\u2026 USING VODKA<\/a><\/li>\n<\/ul>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/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=\"http:\/\/habrahabr.ru\/post\/234909\/\"> http:\/\/habrahabr.ru\/post\/234909\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/e4d\/bbf\/55f\/e4dbbf55fe4b41a6be0500fe74f738f1.png\"\/><\/p>\n<p>  \u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! \u041d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438 \u0440\u0435\u043b\u0438\u0437 PostgreSQL 9.4 \u0438 \u043d\u0435\u043b\u0438\u0448\u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432\u0430\u043c, \u043f\u0440\u0438\u0432\u043d\u0435\u0441\u0451\u043d\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b (\u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, \u043a\u0430\u0441\u0430\u0435\u043c\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438):<\/p>\n<ul>\n<li><a href=\"#autoupdatable_views\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0430\u0432\u0442\u043e\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/a><\/li>\n<li><a href=\"#materialized_views\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445<\/a><\/li>\n<li><a href=\"#alter_system\">\u043a\u043e\u043c\u0430\u043d\u0434\u0430 ALTER SYSTEM \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/a><\/li>\n<li><a href=\"#with_ordinality\">\u043e\u043f\u0446\u0438\u044f WITH ORDINALITY \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a<\/a><\/li>\n<li><a href=\"#aggregate_funcs\">\u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/li>\n<li><a href=\"#gin_gist\">\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 GIN \u0438 GiST<\/a><\/li>\n<li><a href=\"#explain\">\u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b EXPLAIN<\/a><\/li>\n<li><a href=\"#prewarm\">\u0440\u0430\u0437\u043e\u0433\u0440\u0435\u0432 \u043a\u044d\u0448\u0430<\/a><\/li>\n<li><a href=\"#foreign_table_triggers\">\u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446<\/a><\/li>\n<li><a href=\"#json\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f json \u0438 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 jsonb<\/a><\/li>\n<\/ul>\n<p>  <\/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-234909","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/234909","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=234909"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/234909\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}