{"id":314836,"date":"2020-12-14T15:01:18","date_gmt":"2020-12-14T15:01:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=314836"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=314836","title":{"rendered":"PostgreSQL Antipatterns: \u0441\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0439 \u0446\u0435\u043f\u044c\u044e EXISTS"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\u042f \u0443\u0436\u0435 \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/post\/494776\/\">\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432 SQL<\/a> \u0432\u043e\u043e\u0431\u0449\u0435 \u0438 \u0432 PostgreSQL, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0442\u0435\u043c\u0443 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043f\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0443 \u043a\u043e\u0433\u043e \u0438\u0437 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 <b>\u0435\u0441\u0442\u044c<\/b> \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u00ab\u0441\u0443\u043f\u0435\u0440\u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0435\u00bb \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code class=\"sql\">CREATE TABLE task AS SELECT   id , (random() * 100)::integer person -- \u0432\u0441\u0435\u0433\u043e 100 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 , least(trunc(-ln(random()) \/ ln(2)), 10)::integer priority -- \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0432 2 \u0440\u0430\u0437\u0430 \u043c\u0435\u043d\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u0435\u043d FROM   generate_series(1, 1e5) id; -- 100K \u0437\u0430\u0434\u0430\u0447 CREATE INDEX ON task(person, priority); <\/code><\/pre>\n<p>  \u0421\u043b\u043e\u0432\u043e \u00ab\u0435\u0441\u0442\u044c\u00bb \u0432 SQL \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <code>EXISTS<\/code> \u2014 \u0432\u043e\u0442 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438 \u043d\u0430\u0447\u043d\u0435\u043c:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority = 10   ); <\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/c5c3c9c372ba21287c633fb83de026f6:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wu\/p0\/sa\/wup0satqenaq7mlykvleuz5vkme.png\"><\/a><br \/>  <font color=\"#808080\"><i>\u0432\u0441\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u043a\u043b\u0438\u043a\u0430\u0431\u0435\u043b\u044c\u043d\u044b<\/i><\/font><\/p>\n<p>  \u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e\u2026<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>EXISTS + IN<\/h2>\n<p>  \u2026 \u0442\u0443\u0442 \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u0438, \u0438 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043a \u00ab\u0441\u0443\u043f\u0435\u0440\u00bb \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e <code>priority = 10<\/code>, \u043d\u043e \u0435\u0449\u0435 \u0438 8 \u0438 9:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority IN (10, 9, 8)   );<\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/b959a859c426170e273bf6f168026f01:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/6l\/oo\/tw\/6lootwotqvrzlc1gnz9ggzmz2ro.png\"><\/a><\/p>\n<p>  \u0427\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u043b\u0438 \u0432 1.5 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u0443 \u0438 \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c.<\/p>\n<h2>OR + EXISTS<\/h2>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0448\u0438\u043c \u0437\u043d\u0430\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0441 <code>priority = 8<\/code> \u043c\u043d\u043e\u0433\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435, \u0447\u0435\u043c \u0441 10:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority = 8   ) OR   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority = 9   ) OR   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority = 10   ); <\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/7f7359bb8d9058363e53ed644324366e:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xr\/uw\/co\/xruwcoe5ec1h7d1d6mwkkmzphgo.png\"><\/a><\/p>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <b>PostgreSQL 12<\/b> \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 100 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e 8 \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 <code>EXISTS<\/code>-\u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u00ab\u043d\u0435\u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445\u00bb \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u2014 \u0432\u0441\u0435\u0433\u043e 13 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e 9, \u0438 \u043b\u0438\u0448\u044c 4 \u2014 \u043f\u043e 10.<\/p>\n<h4>CASE + EXISTS + &#8230;<\/h4>\n<p>  \u041d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u00ab\u0441\u043f\u0440\u044f\u0442\u0430\u0432 \u043f\u043e\u0434 CASE\u00bb \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   CASE     WHEN       EXISTS(         SELECT           NULL         FROM           task         WHERE           person = pid AND           priority = 8       ) THEN TRUE     ELSE       CASE         WHEN           EXISTS(             SELECT               NULL             FROM               task             WHERE               person = pid AND               priority = 9           ) THEN TRUE         ELSE           EXISTS(             SELECT               NULL             FROM               task             WHERE               person = pid AND               priority = 10           )       END   END; <\/code><\/pre>\n<p>  <\/p>\n<h4>EXISTS + UNION ALL + LIMIT<\/h4>\n<p>  \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0447\u0443\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u00ab\u0445\u0430\u043a\u043e\u043c\u00bb <code>UNION ALL + LIMIT<\/code>:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     (       SELECT         NULL       FROM         task       WHERE         person = pid AND         priority = 8       LIMIT 1     )     UNION ALL     (       SELECT         NULL       FROM         task       WHERE         person = pid AND         priority = 9       LIMIT 1     )     UNION ALL     (       SELECT         NULL       FROM         task       WHERE         person = pid AND         priority = 10       LIMIT 1     )     LIMIT 1   ); <\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/6409ef1b8c38c67fdc03acf236145533:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9k\/dg\/ev\/9kdgevvwagsyp2jsxtvyneolzxg.png\"><\/a><\/p>\n<h2>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u2014 \u0437\u0430\u043b\u043e\u0433 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f \u0431\u0430\u0437\u044b<\/h2>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u0434\u0435\u043c \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u043e\u0432\u0441\u0435\u043c \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u0415\u0441\u043b\u0438 \u043c\u044b \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0442\u0435\u0445 <code>task<\/code>-\u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u0439\u0442\u0438, <b>\u0432 \u0440\u0430\u0437\u044b \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445<\/b> \u2014 \u0442\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441. \u0417\u0430\u043e\u0434\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043e\u0442 \u00ab\u0442\u043e\u0447\u0435\u0447\u043d\u043e\u0433\u043e\u00bb \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <code>8, 9, 10<\/code> \u043a <code>&gt;= 8<\/code>:<\/p>\n<pre><code class=\"sql\">CREATE INDEX ON task(person) WHERE priority &gt;= 8;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority &gt;= 8   );<\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/f16efba95507156781dff515b5839dee:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pb\/mb\/l1\/pbmbl1zuwcinhbm963e6cpy3-r4.png\"><\/a><\/p>\n<p>  \u0412 2 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0432 1.5 \u0440\u0430\u0437\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0447\u0438\u0442\u0430\u0442\u044c!<\/p>\n<p>  \u041d\u043e \u0432\u0435\u0434\u044c, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u0441\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 <code>task<\/code> \u0441\u0440\u0430\u0437\u0443 \u2014 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435?..<\/p>\n<pre><code class=\"sql\">SELECT DISTINCT   person FROM   task WHERE   priority &gt;= 8;<\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/a8df7aecbe335ae410ba70e51f71e71e:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yh\/3h\/-y\/yh3h-y3vkfzopg9ychpe2-gkn5i.png\"><\/a><\/p>\n<p>  \u0414\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430, \u0438 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e 100 \u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u043e\u043f\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 400!  <\/p>\n<hr>\n<p>\u0410 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u0430\u0434\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d, \u0430 \u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u2014 \u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c <a href=\"https:\/\/explain.tensor.ru\/\">explain.tensor.ru<\/a>.<\/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:\/\/habr.com\/ru\/company\/tensor\/blog\/532852\/\"> https:\/\/habr.com\/ru\/company\/tensor\/blog\/532852\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\u042f \u0443\u0436\u0435 \u043a\u0430\u043a-\u0442\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/post\/494776\/\">\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432 SQL<\/a> \u0432\u043e\u043e\u0431\u0449\u0435 \u0438 \u0432 PostgreSQL, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0442\u0435\u043c\u0443 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043f\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0443 \u043a\u043e\u0433\u043e \u0438\u0437 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 <b>\u0435\u0441\u0442\u044c<\/b> \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u00ab\u0441\u0443\u043f\u0435\u0440\u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u044b\u0435\u00bb \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<pre><code class=\"sql\">CREATE TABLE task AS SELECT   id , (random() * 100)::integer person -- \u0432\u0441\u0435\u0433\u043e 100 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 , least(trunc(-ln(random()) \/ ln(2)), 10)::integer priority -- \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u0432 2 \u0440\u0430\u0437\u0430 \u043c\u0435\u043d\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u0435\u043d FROM   generate_series(1, 1e5) id; -- 100K \u0437\u0430\u0434\u0430\u0447 CREATE INDEX ON task(person, priority); <\/code><\/pre>\n<p>  \u0421\u043b\u043e\u0432\u043e \u00ab\u0435\u0441\u0442\u044c\u00bb \u0432 SQL \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <code>EXISTS<\/code> \u2014 \u0432\u043e\u0442 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438 \u043d\u0430\u0447\u043d\u0435\u043c:<\/p>\n<pre><code class=\"sql\">SELECT   * FROM   generate_series(0, 99) pid WHERE   EXISTS(     SELECT       NULL     FROM       task     WHERE       person = pid AND       priority = 10   ); <\/code><\/pre>\n<p>  <a href=\"https:\/\/explain.tensor.ru\/archive\/explain\/c5c3c9c372ba21287c633fb83de026f6:0:2020-12-14\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/wu\/p0\/sa\/wup0satqenaq7mlykvleuz5vkme.png\"><\/a><br \/>  <font color=\"#808080\"><i>\u0432\u0441\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u043a\u043b\u0438\u043a\u0430\u0431\u0435\u043b\u044c\u043d\u044b<\/i><\/font><\/p>\n<p>  \u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e\u2026  <\/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-314836","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314836","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=314836"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314836\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}