{"id":469409,"date":"2025-08-02T21:00:24","date_gmt":"2025-08-02T21:00:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=469409"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=469409","title":{"rendered":"<span>\u041e\u0431 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0431 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e<\/h2>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u043b\u043b\u0435\u0433 \u043f\u043e \u0421\u0423\u0411\u0414 \u0431\u044b\u0442\u043e\u0432\u0430\u043b\u043e \u043c\u043d\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043c\u0430\u043b\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0421\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 (Disk I\/O) \u043d\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 TID (Tuple ID) \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u043e\u043b\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u043e\u043b\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0447\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u0432\u043e\u0439\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443.<br \/> \u0421\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u043c\u043e\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e\u0442 \u043e\u0431\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u043e\u043b\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0449\u0443\u0442\u0438\u043c\u043e\u0433\u043e \u0432\u044b\u0438\u0433\u0440\u044b\u0448\u0430 \u0438\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430. \u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u0435\u0432\u044c\u044e \u0433\u043b\u0430\u0437 \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0441\u044f \u0437\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 boolean-\u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0438 \u0432\u0435\u0441\u044c \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u0431\u044b\u043b \u043f\u0440\u043e\u0442\u0438\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0431 \u044d\u0442\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f B-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0430\u0441\u043f\u0435\u043a\u0442\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445?<\/p>\n<h3>\u0412\u0432\u043e\u0434\u043d\u0430\u044f. \u041d\u043e \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h3>\n<p>\u0410 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c b-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e?<\/p>\n<p>\u0412 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0438\u0435\u043c Soft Delete (\u043c\u044f\u0433\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435) \u2014 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438, \u0430 \u043b\u0438\u0448\u044c \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0438\u043b\u0438 \u0434\u043b\u044f \u0430\u0443\u0434\u0438\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u0435 <code>is_deleted bool default False<\/code> &#8212; \u0444\u043b\u0430\u0433 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u043b\u0430\u0433 \u043f\u0435\u0440\u0435\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 True, \u0430 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <code>where is_deleted = True<\/code>. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u043c <code>deleted_at timestamp default now()<\/code> &#8212; \u0432\u0440\u0435\u043c\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438.<br \/> \u041f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 &#8212; hard delete, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<h4>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Soft Delete:<\/h4>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u0441\u044b\u043b\u043e\u043a (\u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c),<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u0430\u0443\u0434\u0438\u0442\u0430 \u0438 \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438:<\/h4>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446 \u0438  \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445,<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0444\u043b\u0430\u0433 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445,<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u043f\u043e \u043f\u043e\u043b\u044e is_deleted \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u043e\u043b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c True\/False, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0438 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<h3>\u0418\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 PostgreSQL<\/h3>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f &#8212; \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 (\u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0414\u043b\u044f B-Tree \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/> \u0418\u043d\u0434\u0435\u043a\u0441 \u2013 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432) \u0438 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 (TID). \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043e\u0431\u044b\u0447\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u043d\u0435\u0451 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442). \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u0437 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 + \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0434\u0438\u0441\u043a\u0430.<br \/> B-Tree (Balanced Tree, \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e) \u0434\u0435\u0440\u0435\u0432\u043e &#8212; \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u0443\u044e\u0449\u0430\u044f\u0441\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0438\u0441\u043a, \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, O(log N),<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438,<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u0445 (\u0432\u0441\u0435 \u043b\u0438\u0441\u0442\u044c\u044f \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435),<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0436\u0434\u0443 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u0443\u0437\u043b\u044b, \u043b\u0438\u0441\u0442\u044c\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0445\u0440\u0430\u043d\u044f\u0442 \u043a\u043b\u044e\u0447 \u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443. \u0412 PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/B%E2%81%BA-%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE\" rel=\"noopener noreferrer nofollow\">B+ tree<\/a> \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u0438\u0441\u0442 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u0438\u0441\u0442 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (INSERT, UPDATE, DELETE), \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u043e\u0431\u044a\u0451\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u0442\u0438\u043f\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0410\u043d\u0442\u0438\u043f\u043e\u0434\u043e\u043c \u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u043c\u0443 \u043f\u043e\u0438\u0441\u043a\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (sequential scan) \u0441 \u0434\u0438\u0441\u043a\u0430 \u0438\u043b\u0438 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c &#8212; O(N).<\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430<\/h3>\n<p>CPU: i5-1335U<br \/> Disk: SSD SAMSUNG MZAL41T0HBLB-00BLL<\/p>\n<p>\u0421\u0423\u0411\u0414: PostgreSQL 16.9<br \/> \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>pg_hint_plan<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>shared_buffers &#8212; 4 \u0413\u0431<\/p>\n<\/li>\n<li>\n<p>random_page_cost &#8212; 4<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<pre><code>CREATE TABLE tbl_data (     AAA TEXT,     BBB TEXT,     CCC TEXT,     is_deleted bool DEFAULT false NOT NULL ); CREATE INDEX idx_tmp_data_is_deleted ON public.tmp_data USING btree (is_deleted); <\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a. \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0434\u043b\u0438\u043d\u043e\u0439 10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f is_deleted \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u0440\u044c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u043e\u0442 0.01% \u0434\u043e 99.99%. \u0420\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430: 330 \u041c\u0431, \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b: 3.2 \u0413\u0431<br \/> \u041f\u0440\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u043c \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0435\u0440\u0435\u0437 TRUNCATE \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c VACUUM FULL + ANALYZE.<br \/> \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044f \u043f\u043e \u043f\u043e\u043b\u044e is_deleted. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0433\u0440\u0435\u0432\u043e\u043c \u043a\u044d\u0448\u0430. \u0417\u0430\u043c\u0435\u0440\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c (cost) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code>select \/*+ IndexOnlyScan(t idx_tmp_data_is_deleted) *\/ count(1) from tbl_data t where t.is_deleted = true; select \/*+ SeqScan(t) *\/ count(1) from tbl_data t where t.is_deleted = true; <\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c <a href=\"https:\/\/postgrespro.ru\/docs\/postgrespro\/current\/indexes-partial\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/a>. \u0425\u043e\u0442\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c is_deleted = True, \u0442. \u043a. \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0432 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. \u0427\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043d\u0438\u0436\u0430\u0442\u044c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435. (\u041f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f. \u042d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. \u0410 \u0432\u043e\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0447\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438).<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b <a href=\"https:\/\/www.postgresql.org\/docs\/16\/parallel-plans.html#PARALLEL-SCANS\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/a> (\u041f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430, \u0445\u043e\u0442\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b)<\/p>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f True\/False \u0432 \u043f\u043e\u043b\u0435 is_deleted \u043e\u0442 0.01% \u0434\u043e 99.99%<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/dbc\/800\/e82\/dbc800e82bd6efbf077a6f273f5c0a36.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/dbc\/800\/e82\/dbc800e82bd6efbf077a6f273f5c0a36.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/dbc\/800\/e82\/dbc800e82bd6efbf077a6f273f5c0a36.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 1. <\/p>\n<p>\u041f\u043e \u043e\u0441\u0438 X \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u0430 \u0434\u043e\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c True \u0432 \u043f\u043e\u043b\u0435 is_deleted. \u041f\u043e \u043e\u0441\u0438 Y &#8212; \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (psql \\timing).<\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 True \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u044f\u0441\u044c \u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (Seq Scan). \u0418\u043d\u0434\u0435\u043a\u0441 \u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0420\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a \u0441\u043b\u0443\u0447\u0430\u044e \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0442.\u0435. \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 &#171;\u0411\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430&#187; \/ &#171;\u0421 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c&#187;: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/b54\/9b0\/a36\/b549b0a369eb10695beb7e9fdcecd77c.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/b54\/9b0\/a36\/b549b0a369eb10695beb7e9fdcecd77c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/b54\/9b0\/a36\/b549b0a369eb10695beb7e9fdcecd77c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 2. <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439. \u0414\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c. \u0414\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a \u0434\u043b\u044f &#171;\u0414\u043e\u043b\u044f True&#187; &gt; 5%:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/0f4\/3ff\/c89\/0f43ffc89a4d57f09b0357645689b19d.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/0f4\/3ff\/c89\/0f43ffc89a4d57f09b0357645689b19d.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/0f4\/3ff\/c89\/0f43ffc89a4d57f09b0357645689b19d.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 3. <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043b\u044f True \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 99.99%, \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u0447\u0442\u0438 \u0432 1.4 \u0440\u0430\u0437\u0430, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e.<\/p>\n<h3>\u041e \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f 50% True:<br \/> <code>explain (analyze, verbose, buffers, settings, format text) SELECT \/*+ IndexOnlyScan(t idx_tbl_data_is_deleted) *\/ count(1) FROM tbl_data AS t where t.is_deleted = true; <\/code><\/p>\n<pre><code> Finalize Aggregate  (cost=404176.00..404176.01 rows=1 width=8) (actual time=576.711..583.116 rows=1 loops=1)    Output: count(1)    Buffers: shared hit=21086    -&gt;  Gather  (cost=404175.78..404175.99 rows=2 width=8) (actual time=576.566..583.094 rows=3 loops=1)          Output: (PARTIAL count(1))          Workers Planned: 2          Workers Launched: 2          Buffers: shared hit=21086          -&gt;  Partial Aggregate  (cost=403175.78..403175.79 rows=1 width=8) (actual time=563.323..563.323 rows=1 loops=3)                Output: PARTIAL count(1)                Buffers: shared hit=21086                Worker 0:  actual time=556.752..556.752 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining false, Optimization false, Expressions true, Deforming true                    Timing: Generation 0.407 ms, Inlining 0.000 ms, Optimization 0.130 ms, Emission 2.069 ms, Total 2.606 ms                  Buffers: shared hit=7723                Worker 1:  actual time=556.781..556.782 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining false, Optimization false, Expressions true, Deforming true                    Timing: Generation 0.399 ms, Inlining 0.000 ms, Optimization 0.115 ms, Emission 1.780 ms, Total 2.294 ms                  Buffers: shared hit=5441                -&gt;  Parallel Index Only Scan using idx_tbl_data_is_deleted on public.tbl_data t  (cost=0.56..377078.71 rows=10438827 width=0) (actual time=0.249..332.615 rows=8332717 loops=3)                      Output: is_deleted                      Index Cond: (t.is_deleted = true)                      Heap Fetches: 59                      Buffers: shared hit=21086                      Worker 0:  actual time=0.698..322.261 rows=9159480 loops=1                        Buffers: shared hit=7723                      Worker 1:  actual time=0.029..341.285 rows=6447846 loops=1                        Buffers: shared hit=5441  Settings: work_mem = '128MB'  Planning Time: 0.072 ms  JIT:    Functions: 11    Options: Inlining false, Optimization false, Expressions true, Deforming true    Timing: Generation 0.972 ms, Inlining 0.000 ms, Optimization 0.345 ms, Emission 5.689 ms, Total 7.006 ms  Execution Time: 583.344 ms (39 rows) <\/code><\/pre>\n<p>\u041d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c &#8212; <a href=\"https:\/\/www.postgresql.org\/docs\/current\/using-explain.html\" rel=\"noopener noreferrer nofollow\">Parallel Index Only Scan<\/a> \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 Heap Fetches.<br \/> <code>Parallel Index Only Scan<\/code> &#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 PostgreSQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0430\u043c\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 (heap). \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 (\u0432 \u043a\u043b\u044e\u0447\u0435).<br \/> <code>Heap Fetches<\/code> &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (heap), \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<p>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f 50% True:<br \/> `explain (analyze, verbose, buffers, settings, format text) SELECT \/*+ SeqScan(t) *\/ count(1) FROM tbl_data AS t where t.is_deleted = true;<\/p>\n<pre><code> Finalize Aggregate  (cost=652094.37..652094.38 rows=1 width=8) (actual time=3295.404..3300.655 rows=1 loops=1)    Output: count(1)    Buffers: shared hit=417 read=416248    -&gt;  Gather  (cost=652094.15..652094.36 rows=2 width=8) (actual time=3295.308..3300.634 rows=3 loops=1)          Output: (PARTIAL count(1))          Workers Planned: 2          Workers Launched: 2          Buffers: shared hit=417 read=416248          -&gt;  Partial Aggregate  (cost=651094.15..651094.16 rows=1 width=8) (actual time=3285.027..3285.028 rows=1 loops=3)                Output: PARTIAL count(1)                Buffers: shared hit=417 read=416248                Worker 0:  actual time=3282.244..3282.244 rows=1 loops=1                  JIT:                    Functions: 4                    Options: Inlining true, Optimization true, Expressions true, Deforming true                    Timing: Generation 0.238 ms, Inlining 32.262 ms, Optimization 10.816 ms, Emission 9.892 ms, Total 53.207 ms                  Buffers: shared hit=121 read=135897                Worker 1:  actual time=3277.699..3277.700 rows=1 loops=1                  JIT:                    Functions: 4                    Options: Inlining true, Optimization true, Expressions true, Deforming true                    Timing: Generation 0.332 ms, Inlining 48.248 ms, Optimization 10.815 ms, Emission 9.017 ms, Total 68.411 ms                  Buffers: shared hit=163 read=137976                -&gt;  Parallel Seq Scan on public.tbl_data t  (cost=0.00..624997.08 rows=10438827 width=0) (actual time=50.867..3053.389 rows=8332717 loops=3)                      Output: aaa, bbb, ccc, is_deleted                      Filter: t.is_deleted                      Rows Removed by Filter: 8333849                      Buffers: shared hit=417 read=416248                      Worker 0:  actual time=55.735..3049.628 rows=8160368 loops=1                        Buffers: shared hit=121 read=135897                      Worker 1:  actual time=68.180..3052.262 rows=8290198 loops=1                        Buffers: shared hit=163 read=137976  Settings: work_mem = '128MB'  Planning Time: 0.096 ms  JIT:    Functions: 14    Options: Inlining true, Optimization true, Expressions true, Deforming true    Timing: Generation 0.843 ms, Inlining 83.418 ms, Optimization 36.309 ms, Emission 30.031 ms, Total 150.601 ms  Execution Time: 3301.000 ms (39 rows)  Time: 3302.107 ms (00:03.302) <\/code><\/pre>\n<p>\u0418\u0437 \u043f\u043b\u0430\u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0438\u0442\u0430\u043b\u0430\u0441\u044c \u0441 \u0434\u0438\u0441\u043a\u0430, \u0447\u0442\u043e \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430.<\/p>\n<h3>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443<\/h3>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u043f\u043e \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0434\u0435 True \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 95% \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c 50 \u043c\u043b\u043d \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>select count(1) from tbl_data t where t.is_deleted = false; <\/code><\/pre>\n<p>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code> Finalize Aggregate  (cost=1078406.12..1078406.13 rows=1 width=8)    -&gt;  Gather  (cost=1078405.91..1078406.12 rows=2 width=8)          Workers Planned: 2          -&gt;  Partial Aggregate  (cost=1077405.91..1077405.92 rows=1 width=8)                -&gt;  Parallel Seq Scan on tbl_data t  (cost=0.00..1028006.55 rows=19759743 width=0)                      Filter: (NOT is_deleted)  <\/code><\/pre>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430: 0.793 \u0441.<br \/> \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 Index Only Scan. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 pg_hint_plan \u0438 \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0445\u0438\u043d\u0442\u043e\u043c IndexOnlyScan:<\/p>\n<pre><code>select \/*+ IndexOnlyScan(t idx_tbl_data_is_deleted) *\/ count(1) from tbl_data t where t.is_deleted = false; <\/code><\/pre>\n<p>\u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: 1.022 \u0441<\/p>\n<p>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code> Finalize Aggregate  (cost=15287926.97..15287926.98 rows=1 width=8) (actual time=4860.161..4869.313 rows=1 loops=1)    Output: count(1)    -&gt;  Gather  (cost=15287926.76..15287926.97 rows=2 width=8) (actual time=4860.008..4869.294 rows=3 loops=1)          Output: (PARTIAL count(1))          Workers Planned: 2          Workers Launched: 2          -&gt;  Partial Aggregate  (cost=15286926.76..15286926.77 rows=1 width=8) (actual time=4842.191..4842.192 rows=1 loops=3)                Output: PARTIAL count(1)                Worker 0:  actual time=4832.626..4832.627 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining true, Optimization true, Expressions true, Deforming true                    Timing: Generation 0.247 ms, Inlining 45.698 ms, Optimization 2.478 ms, Emission 3.991 ms, Total 52.415 ms                Worker 1:  actual time=4834.112..4834.112 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining true, Optimization true, Expressions true, Deforming true                    Timing: Generation 1.046 ms, Inlining 33.225 ms, Optimization 2.506 ms, Emission 4.128 ms, Total 40.905 ms                -&gt;  Parallel Index Only Scan using idx_tbl_data_is_deleted on public.tbl_data t  (cost=0.56..15237527.40 rows=19759743 width=0) (actual time=4.460..4419.006 rows=15832631 loops=3)                      Output: is_deleted                      Index Cond: (t.is_deleted = false)                      Heap Fetches: 47497894                      Worker 0:  actual time=0.186..4397.416 rows=15986916 loops=1                      Worker 1:  actual time=0.115..4410.642 rows=15082848 loops=1 <\/code><\/pre>\n<p>\u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430 Index Only Scan \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0437\u0430\u043c\u0435\u0434\u043b\u0435\u043d\u0438\u0435:<br \/> \u041f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: +29%, \u043f\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 (cost): 1417%.<\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Index Scan \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 Index Scan Only \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043d\u0430 30% (\u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f) \u0438 \u043d\u0430 1417% (\u043f\u043e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438, cost).<br \/> \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u041a\u0430\u0440\u0442\u0430 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (Visibility Map) \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b VACUUM, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c <code>autovacuum<\/code>.<\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 <code>autovacuum<\/code>:<\/p>\n<pre><code>SELECT schemaname, relname, n_dead_tup, n_live_tup, last_autovacuum, last_autoanalyze, autovacuum_count, round(n_dead_tup::float \/ n_live_tup::float * 100) AS dead_pct FROM pg_stat_all_tables WHERE relname = 'tbl_data'; <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f autovacuum:<\/p>\n<pre><code>db=# SELECT * FROM pg_stat_progress_vacuum;   pid  | datid | datname | relid  |     phase     | heap_blks_total | heap_blks_scanned | heap_blks_vacuumed | index_vacuum_count | max_dead_tuples | num_dead_tuples  -------+-------+---------+--------+---------------+-----------------+-------------------+--------------------+--------------------+-----------------+-----------------  38518 | 16388 | db      | 204569 | scanning heap |          416667 |             76586 |                  0 |                  0 |        11184809 |             100 (1 row)  Time: 8.296 ms <\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e? \u041f\u043e \u0438\u0434\u0435\u0435, \u0435\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 (\u0440\u0430\u0437\u043c\u0435\u0440 330 \u041c\u0431) \u043c\u0435\u043d\u044c\u0448\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (\u0440\u0430\u0437\u043c\u0435\u0440 6404 \u041c\u0431), \u0430 \u0421\u0423\u0411\u0414 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0432 \u043f\u043b\u0430\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u0432\u0438\u0434\u0438\u043c: <code>Heap Fetches: 47497894<\/code>. \u042d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0438\u043d\u0434\u0435\u043a\u0441, \u0430 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 95% \u0441\u0442\u0440\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<br \/> \u041d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 Index Only Scan \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043a\u0430\u043a Index Scan?<br \/> <code>Index Only Scan<\/code>  \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043f\u0440\u0438\u0437\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043f\u0440\u0438 \u043d\u0435\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0440\u044f\u0434\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u043e\u043d \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 <code>Index Scan<\/code> \u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 (heap). \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u0432 \u043a\u0430\u0440\u0442\u0435 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (Visibility Map) \u043a\u0430\u043a \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430\u044f. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430\u044f \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/15\/storage-vm\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0442 \u043a\u0430\u0440\u0442\u044b \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, all-visible<\/a>, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 \u043a\u043b\u044e\u0447\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 &#8212; \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u0438\u0441\u043a \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c &#171;\u0441\u0445\u043e\u0434\u0438\u0442\u044c&#187; \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 (heap), \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c.<br \/> \u0411\u0438\u0442 all-visible &#8212; \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u0438\u0434\u0438\u043c\u044b \u0432\u0441\u0435\u043c \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f\u043c, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0435\u0440\u0442\u0432\u044b\u0445 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (tuples) \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0447\u0438\u0441\u0442\u043a\u0438. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 ( <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/15\/storage-vm\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespro.ru\/docs\/postgresql\/15\/storage-vm<\/a> ):<\/p>\n<pre><code>\u0411\u0438\u0442\u044b \u043a\u0430\u0440\u0442\u044b \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438\u00a0\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0435, \u0430\u00a0\u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445, \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0435\u00a0\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. <\/code><\/pre>\n<h3>Planner\/Optimizer \u0438 \u0435\u0433\u043e \u043e\u0446\u0435\u043d\u043a\u0438 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h3>\n<p>\u0410 \u0447\u0442\u043e \u0436\u0435 \u0441 \u043e\u0446\u0435\u043d\u043a\u0430\u043c\u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 <a href=\"https:\/\/www.postgresql.org\/docs\/16\/planner-optimizer.html\" rel=\"noopener noreferrer nofollow\">Planner\/Optimizer<\/a>? \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u0438\u0435 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u043d\u044b\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u043e\u043d \u0434\u0430\u0432\u0430\u043b \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/101\/181\/419\/101181419932a896dc0fddff3d3811e7.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/101\/181\/419\/101181419932a896dc0fddff3d3811e7.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/101\/181\/419\/101181419932a896dc0fddff3d3811e7.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 4. <\/p>\n<p>\u0412\u0438\u0434\u0438\u043c \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0440\u043e\u0441\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u043e &#8212; \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0412 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0435\u0441\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442 (\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043b\u0438\u043d\u0438\u0439, \u0434\u043e\u043b\u044f True = ~85%), \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e Index Only Scan \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0443 Seq Scan. \u041f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u043a\u043e\u0433\u0434\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441\u0430\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u043b \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u0442. \u0435. \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0445\u0438\u043d\u0442\u044b <a href=\"https:\/\/postgrespro.ru\/docs\/enterprise\/current\/pg-hint-plan\" rel=\"noopener noreferrer nofollow\">SeqScan<\/a>, <a href=\"https:\/\/postgrespro.ru\/docs\/enterprise\/current\/pg-hint-plan\" rel=\"noopener noreferrer nofollow\">IndexOnlyScan<\/a>: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/219\/d17\/599\/219d17599057a967c60b85c101f56c4d.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/219\/d17\/599\/219d17599057a967c60b85c101f56c4d.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/219\/d17\/599\/219d17599057a967c60b85c101f56c4d.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 5. <\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043e\u0448\u0438\u0431\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c <a href=\"https:\/\/www.postgresql.org\/docs\/current\/using-explain.html\" rel=\"noopener noreferrer nofollow\">Seq Scan<\/a> \u0434\u043b\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 True &gt;= 85%, \u0445\u043e\u0442\u044f \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u0440\u0438\u0441. 1, \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0432 1.43 \u0440\u0430\u0437\u0430.<\/p>\n<p>\u0410 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u043f\u0440\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043e\u0442 100 \u0441\u0442\u0440\u043e\u043a \u0434\u043e 100 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a \u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c 2 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f True\/False: 5% \u0438 50% \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f &#171;\u0421 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c&#187;: <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/b50\/3f9\/ad5\/b503f9ad5d0352ccd57626cc4400118a.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/\/post_images\/b50\/3f9\/ad5\/b503f9ad5d0352ccd57626cc4400118a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/\/post_images\/b50\/3f9\/ad5\/b503f9ad5d0352ccd57626cc4400118a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p> \u0420\u0438\u0441 6. <\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0441\u0435\u0431\u044f \u0432\u0435\u0434\u0435\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f True (5%) \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0434\u043b\u044f \u043d\u0438\u0437\u043a\u043e\u0439 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (50%).<\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 SSD \u0434\u0438\u0441\u043a\u0430\u0445, \u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0421\u0423\u0411\u0414 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u043b\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 HDD:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/runtime-config-query\" rel=\"noopener noreferrer nofollow\">random_page_cost<\/a> (default 4.0) &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c (\u0432 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445) \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u043b\u0430\u043d\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 4 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 HDD, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u044d\u0444\u0444\u0435\u043a\u0442 \u0431\u0443\u0442\u044b\u043b\u043e\u0447\u043d\u043e\u0433\u043e \u0433\u043e\u0440\u043b\u044b\u0448\u043a\u0430. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 SSD \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f [<a href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-query.html\" rel=\"noopener noreferrer nofollow\">1<\/a>] [<a href=\"https:\/\/interface31.ru\/tech_it\/2020\/03\/optimizaciya-proizvoditel-nosti-postgresql-dlya-raboty-s-1spredpriyatie.html\" rel=\"noopener noreferrer nofollow\">2<\/a>] \u0441\u043d\u0438\u0436\u0430\u0442\u044c random_page_cost \u0434\u043e 1.1\u20131.3 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043d\u0438\u0436\u0435 (0.5 \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 SSD \u0438 0.1 \u0434\u043b\u044f NVMe).<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/runtime-config-query\" rel=\"noopener noreferrer nofollow\">seq_page_cost<\/a> (default 1.0) &#8212; \u0437\u0430\u0434\u0430\u0451\u0442 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u0434\u0438\u0441\u043a\u0430 (\u0432 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u0440\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0442\u0435\u043d\u0438\u0439. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 random_page_cost \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 random_page_cost \/ seq_page_cost \u2248 2\u20134 .<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442, \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0445 DML-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0439 &#8212; \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442 \u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <code>autovacuum<\/code>, \u0438\u043d\u0430\u0447\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (SeqScan). \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c\u044b\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0440\u0430\u043d\u044c\u0448\u0435, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 VACUUM, \u0442.\u043a. \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u044b \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 <code>autovacuum<\/code> (\u0441\u043c \u043f\u043e\u043b\u0435 pg_stat_all_tables.last_autovacuum).<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<ol>\n<li>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0435\u043c\u0430 <code>Soft delete<\/code> \u0432 \u0421\u0423\u0411\u0414 PostgreSQL \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0441\u0442\u0440\u043e\u0438\u0442\u044c B-Tree-\u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e <code>is_deleted bool<\/code> (\u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u0444\u0430\u043a\u0442\u043e\u0440\u044b \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u0435 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c). \u0418\u043d\u0434\u0435\u043a\u0441 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c <a href=\"https:\/\/postgrespro.ru\/docs\/postgrespro\/current\/indexes-partial\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u043c<\/a> \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e False:<\/p>\n<\/li>\n<\/ol>\n<pre><code>CREATE INDEX idx_tbl_data_is_deleted ON tbl_data (is_deleted) WHERE is_deleted = false; <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 SSD-\u0434\u0438\u0441\u043a\u0430\u0445 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c <a href=\"https:\/\/postgrespro.ru\/docs\/postgresql\/16\/runtime-config-query\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u0441\u043b\u0435 \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>autovacuum<\/code> \u0438 <code>autoanalyze<\/code> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438: autovacuum_vacuum_threshold, autovacuum_vacuum_scale_factor, autovacuum_analyze_threshold, autovacuum_analyze_scale_factor.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/h2>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/postgrespro\/articles\/326096\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/companies\/postgrespro\/articles\/326096\/<\/a><br \/> <a href=\"https:\/\/postgrespro.ru\/docs\/postgrespro\/9.5\/storage-vm\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespro.ru\/docs\/postgrespro\/9.5\/storage-vm<\/a><br \/> <a href=\"https:\/\/habr.com\/ru\/companies\/tensor\/articles\/751458\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/companies\/tensor\/articles\/751458\/<\/a><br \/> <a href=\"https:\/\/postgrespro.ru\/docs\/enterprise\/current\/pg-hint-plan\" rel=\"noopener noreferrer nofollow\">https:\/\/postgrespro.ru\/docs\/enterprise\/current\/pg-hint-plan<\/a><br \/> <a href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-query.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.postgresql.org\/docs\/current\/runtime-config-query.html<\/a><br \/> <a href=\"https:\/\/interface31.ru\/tech_it\/2020\/03\/optimizaciya-proizvoditel-nosti-postgresql-dlya-raboty-s-1spredpriyatie.html\" rel=\"noopener noreferrer nofollow\">https:\/\/interface31.ru\/tech_it\/2020\/03\/optimizaciya-proizvoditel-nosti-postgresql-dlya-raboty-s-1spredpriyatie.html<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/933480\/\"> https:\/\/habr.com\/ru\/articles\/933480\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0431 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e<\/h2>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0441\u0440\u0435\u0434\u0438 \u043a\u043e\u043b\u043b\u0435\u0433 \u043f\u043e \u0421\u0423\u0411\u0414 \u0431\u044b\u0442\u043e\u0432\u0430\u043b\u043e \u043c\u043d\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043c\u0430\u043b\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0421\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 (Disk I\/O) \u043d\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0435, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 TID (Tuple ID) \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u043e\u043b\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0430 \u043f\u043e\u0442\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0434\u043e\u043b\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0434\u0435\u0448\u0435\u0432\u043b\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0447\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u0432\u043e\u0439\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443.<br \/> \u0421\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u043c\u043e\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e\u0442 \u043e\u0431\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u043e\u043b\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0449\u0443\u0442\u0438\u043c\u043e\u0433\u043e \u0432\u044b\u0438\u0433\u0440\u044b\u0448\u0430 \u0438\u043b\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430. \u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u0435\u0432\u044c\u044e \u0433\u043b\u0430\u0437 \u0437\u0430\u0446\u0435\u043f\u0438\u043b\u0441\u044f \u0437\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 boolean-\u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0438 \u0432\u0435\u0441\u044c \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u0431\u044b\u043b \u043f\u0440\u043e\u0442\u0438\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0431 \u044d\u0442\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f B-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u0445 \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0430\u0441\u043f\u0435\u043a\u0442\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445?<\/p>\n<h3>\u0412\u0432\u043e\u0434\u043d\u0430\u044f. \u041d\u043e \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h3>\n<p>\u0410 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c b-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043f\u043e\u043b\u044e \u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e?<\/p>\n<p>\u0412 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u0440\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0438\u0435\u043c Soft Delete (\u043c\u044f\u0433\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435) \u2014 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438, \u0430 \u043b\u0438\u0448\u044c \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0433\u043e \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0438\u043b\u0438 \u0434\u043b\u044f \u0430\u0443\u0434\u0438\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u0435 <code>is_deleted bool default False<\/code> &#8212; \u0444\u043b\u0430\u0433 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u043b\u0430\u0433 \u043f\u0435\u0440\u0435\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 True, \u0430 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 <code>where is_deleted = True<\/code>. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u043c <code>deleted_at timestamp default now()<\/code> &#8212; \u0432\u0440\u0435\u043c\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438.<br \/> \u041f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 &#8212; hard delete, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<h4>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Soft Delete:<\/h4>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439,<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u0441\u044b\u043b\u043e\u043a (\u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c),<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u0430\u0443\u0434\u0438\u0442\u0430 \u0438 \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438:<\/h4>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446 \u0438  \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445,<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0444\u043b\u0430\u0433 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445,<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u043f\u043e \u043f\u043e\u043b\u044e is_deleted \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u043e\u043b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c True\/False, \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0438 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<h3>\u0418\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 PostgreSQL<\/h3>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f &#8212; \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 (\u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0414\u043b\u044f B-Tree \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/> \u0418\u043d\u0434\u0435\u043a\u0441 \u2013 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432) \u0438 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 (TID). \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043e\u0431\u044b\u0447\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u043d\u0435\u0451 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442). \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u0437 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0434\u0435\u0440\u0435\u0432\u0443 + \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0434\u0438\u0441\u043a\u0430.<br \/> B-Tree (Balanced Tree, \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e) \u0434\u0435\u0440\u0435\u0432\u043e &#8212; \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u0443\u044e\u0449\u0430\u044f\u0441\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0438\u0441\u043a, \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, O(log N),<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438,<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u0445 (\u0432\u0441\u0435 \u043b\u0438\u0441\u0442\u044c\u044f \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435),<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0436\u0434\u0443 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u0443\u0437\u043b\u044b, \u043b\u0438\u0441\u0442\u044c\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0445\u0440\u0430\u043d\u044f\u0442 \u043a\u043b\u044e\u0447 \u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443. \u0412 PostgreSQL \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/B%E2%81%BA-%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE\" rel=\"noopener noreferrer nofollow\">B+ tree<\/a> \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u0438\u0441\u0442 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u0438\u0441\u0442 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (INSERT, UPDATE, DELETE), \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u043e\u0431\u044a\u0451\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u0442\u0438\u043f\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0410\u043d\u0442\u0438\u043f\u043e\u0434\u043e\u043c \u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u043e\u043c\u0443 \u043f\u043e\u0438\u0441\u043a\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (sequential scan) \u0441 \u0434\u0438\u0441\u043a\u0430 \u0438\u043b\u0438 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c &#8212; O(N).<\/p>\n<h3>\u0423\u0441\u043b\u043e\u0432\u0438\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430<\/h3>\n<p>CPU: i5-1335U<br \/> Disk: SSD SAMSUNG MZAL41T0HBLB-00BLL<\/p>\n<p>\u0421\u0423\u0411\u0414: PostgreSQL 16.9<br \/> \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>pg_hint_plan<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>shared_buffers &#8212; 4 \u0413\u0431<\/p>\n<\/li>\n<li>\n<p>random_page_cost &#8212; 4<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<pre><code>CREATE TABLE tbl_data (     AAA TEXT,     BBB TEXT,     CCC TEXT,     is_deleted bool DEFAULT false NOT NULL ); CREATE INDEX idx_tmp_data_is_deleted ON public.tmp_data USING btree (is_deleted); <\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, 50 \u043c\u043b\u043d \u0441\u0442\u0440\u043e\u043a. \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0434\u043b\u0438\u043d\u043e\u0439 10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f is_deleted \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u0440\u044c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u043e\u0442 0.01% \u0434\u043e 99.99%. \u0420\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430: 330 \u041c\u0431, \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b: 3.2 \u0413\u0431<br \/> \u041f\u0440\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u043c \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0435\u0440\u0435\u0437 TRUNCATE \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c VACUUM FULL + ANALYZE.<br \/> \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044f \u043f\u043e \u043f\u043e\u043b\u044e is_deleted. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0433\u0440\u0435\u0432\u043e\u043c \u043a\u044d\u0448\u0430. \u0417\u0430\u043c\u0435\u0440\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c (cost) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code>select \/*+ IndexOnlyScan(t idx_tmp_data_is_deleted) *\/ count(1) from tbl_data t where t.is_deleted = true; select \/*+ SeqScan(t) *\/ count(1) from tbl_data t where t.is_deleted = true; <\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c <a href=\"https:\/\/postgrespro.ru\/docs\/postgrespro\/current\/indexes-partial\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b<\/a>. \u0425\u043e\u0442\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c is_deleted = True, \u0442. \u043a. \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0432 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435. \u0427\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043d\u0438\u0436\u0430\u0442\u044c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435. (\u041f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0441\u044f. \u042d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f. \u0410 \u0432\u043e\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0447\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438).<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b <a href=\"https:\/\/www.postgresql.org\/docs\/16\/parallel-plans.html#PARALLEL-SCANS\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/a> (\u041f\u0440\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430, \u0445\u043e\u0442\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b)<\/p>\n<h3>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f True\/False \u0432 \u043f\u043e\u043b\u0435 is_deleted \u043e\u0442 0.01% \u0434\u043e 99.99%<\/p>\n<figure class=\"\"><\/figure>\n<p> \u0420\u0438\u0441 1. <\/p>\n<p>\u041f\u043e \u043e\u0441\u0438 X \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u0430 \u0434\u043e\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c True \u0432 \u043f\u043e\u043b\u0435 is_deleted. \u041f\u043e \u043e\u0441\u0438 Y &#8212; \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (psql \\timing).<\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0441\u0442\u0435\u0442 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 True \u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u044f\u0441\u044c \u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (Seq Scan). \u0418\u043d\u0434\u0435\u043a\u0441 \u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0420\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0430\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a \u0441\u043b\u0443\u0447\u0430\u044e \u0431\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0442.\u0435. \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 &#171;\u0411\u0435\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u0430&#187; \/ &#171;\u0421 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c&#187;: <\/p>\n<figure class=\"\"><\/figure>\n<p> \u0420\u0438\u0441 2. <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u0443\u0435\u0442\u0441\u044f \u0441 \u0442\u0435\u043e\u0440\u0438\u0435\u0439. \u0414\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043a\u043e\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 True \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c. \u0414\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a \u0434\u043b\u044f &#171;\u0414\u043e\u043b\u044f True&#187; &gt; 5%:<\/p>\n<figure class=\"\"><\/figure>\n<p> \u0420\u0438\u0441 3. <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043b\u044f True \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 99.99%, \u0438\u043d\u0434\u0435\u043a\u0441 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u0447\u0442\u0438 \u0432 1.4 \u0440\u0430\u0437\u0430, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e.<\/p>\n<h3>\u041e \u0440\u0430\u0431\u043e\u0442\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f 50% True:<br \/> <code>explain (analyze, verbose, buffers, settings, format text) SELECT \/*+ IndexOnlyScan(t idx_tbl_data_is_deleted) *\/ count(1) FROM tbl_data AS t where t.is_deleted = true; <\/code><\/p>\n<pre><code> Finalize Aggregate  (cost=404176.00..404176.01 rows=1 width=8) (actual time=576.711..583.116 rows=1 loops=1)    Output: count(1)    Buffers: shared hit=21086    -&gt;  Gather  (cost=404175.78..404175.99 rows=2 width=8) (actual time=576.566..583.094 rows=3 loops=1)          Output: (PARTIAL count(1))          Workers Planned: 2          Workers Launched: 2          Buffers: shared hit=21086          -&gt;  Partial Aggregate  (cost=403175.78..403175.79 rows=1 width=8) (actual time=563.323..563.323 rows=1 loops=3)                Output: PARTIAL count(1)                Buffers: shared hit=21086                Worker 0:  actual time=556.752..556.752 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining false, Optimization false, Expressions true, Deforming true                    Timing: Generation 0.407 ms, Inlining 0.000 ms, Optimization 0.130 ms, Emission 2.069 ms, Total 2.606 ms                  Buffers: shared hit=7723                Worker 1:  actual time=556.781..556.782 rows=1 loops=1                  JIT:                    Functions: 3                    Options: Inlining false, Optimization false, Expressions true, Deforming true                    Timing: Generation 0.399 ms, Inlining 0.000 ms, Optimization 0.115 ms, Emission 1.780 ms, Total 2.294 ms                  Buffers: shared hit=5441                -&gt;  Parallel Index Only Scan using idx_tbl_data_is_deleted on public.tbl_data t  (cost=0.56..377078.71 rows=10438827 width=0) (actual time=0.249..332.615 rows=8332717 loops=3)                      Output: is_deleted                      Index Cond: (t.is_deleted = true)                      Heap Fetches: 59                      Buffers: shared hit=21086                      Worker 0:  actual time=0.698..322.261 rows=9159480 loops=1                        Buffers: shared hit=7723                      Worker 1:  actual time=0.029..341.285 rows=6447846 loops=1                        Buffers: shared hit=5441  Settings: work_mem = '128MB'  Planning Time: 0.072 ms  JIT:    Functions: 11    Options: Inlining false, Optimization false, Expressions true, Deforming true    Timing: Generation 0.972 ms, Inlining 0.000 ms, Optimization 0.345 ms, Emission 5.689 ms, Total 7.006 ms  Execution Time: 583.344 ms (39 rows) <\/code><\/pre>\n<p>\u041d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-469409","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469409","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=469409"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469409\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=469409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=469409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=469409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}