{"id":327322,"date":"2022-01-10T08:50:57","date_gmt":"2022-01-10T08:50:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327322"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327322","title":{"rendered":"<span>\u041a\u0430\u043a \u043c\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 i-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0430 \u043d\u0430\u0448\u043b\u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0430 \u0441\u044b\u0440\u043e\u043c SQL, \u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (ORM). \u041e\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b,\u00a0 \u0438 \u0441\u00a0 \u0440\u043e\u0441\u0442\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0442\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041a\u0430\u043a \u0440\u0430\u0437 \u0432 \u0445\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0430, \u0447\u0442\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Django \u0441 \u043d\u0430\u043c\u0438 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0447\u0435\u0441\u0442\u043d\u0430.<\/strong><\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u044c\u0431\u0438\u043d\u0430 \u0410\u043b\u044c\u043c\u0443\u0445\u0430\u043c\u0435\u0442\u043e\u0432\u0430, \u044f python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u0446\u0430 \u0432 \u0422\u0435\u0445\u043d\u043e\u043a\u0440\u0430\u0442\u0438\u0438. \u041e \u0432\u0432\u043e\u0434\u044f\u0449\u0435\u0439 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django \u044f <a href=\"https:\/\/www.youtube.com\/watch?v=kq-1PzEE4IQ&amp;ab_channel=%D0%92%D0%B8%D0%B4%D0%B5%D0%BE%D1%81%D0%BA%D0%BE%D0%BD%D1%84%D0%B5%D1%80%D0%B5%D0%BD%D1%86%D0%B8%D0%B9IT-People\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0430<\/u><\/a> \u043d\u0430 Pycon \u0432 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443. \u042d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442 \u2014 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u044f \u043c\u043e\u0435\u0433\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0437\u0430\u043d\u044f\u0442, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0438\u0434\u0435\u043e. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0430 \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432\u0438\u0434\u0435\u043e-\u0434\u043e\u043a\u043b\u0430\u0434\u0435, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043d\u0430\u0448\u0438 \u0437\u0440\u0438\u0442\u0435\u043b\u0438. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0434\u043e\u043a\u043b\u0430\u0434, \u0441\u043c\u0435\u043b\u043e \u043b\u0438\u0441\u0442\u0430\u0439\u0442\u0435 \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0443 \u201c\u0417\u0430\u043c\u0435\u0442\u043a\u0438 \u0441 \u0434\u043e\u043a\u043b\u0430\u0434\u0430\u201d \u0438 \u0438\u0437\u0443\u0447\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.\u00a0<\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044f \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u043b\u0430 \u043d\u0430 Pycon, \u0442\u043e \u0432\u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/61c98de54615593b75e247ca\" data-style=\"\" id=\"61c98de54615593b75e247ca\" width=\"\"><\/div>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0445\u043e\u0447\u0443 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u041f\u0430\u0432\u043b\u0443 \u0413\u0430\u0440\u043a\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435:<\/p>\n<ol>\n<li>\n<p><a href=\"#1\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/2\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21161 &#8212; db_index=True<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21162 \u2013 \u0441\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#5\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21163 \u2014 Trigram<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#7\" rel=\"noopener noreferrer nofollow\">\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#8\" rel=\"noopener noreferrer nofollow\">Django 3.2<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#9\" rel=\"noopener noreferrer nofollow\">\u0411\u043e\u043d\u0443\u0441. \u0417\u0430\u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u043b\u0430\u0434\u0430<\/a><\/p>\n<\/li>\n<\/ol>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430  <\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u2014 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0438 \u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u043b\u0438\u0448\u044c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043f\u043e\u0438\u0441\u043a \u0431\u044b\u0441\u0442\u0440\u044b\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u0432 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 Django-\u0430\u0434\u043c\u0438\u043d\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 Django \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0430\u0434\u043c\u0438\u043d\u043a\u0438, \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0434\u043e\u043b\u0433\u043e \u0436\u0434\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441 \u043d\u0435\u0435 \u0443\u0439\u0442\u0438 (\u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0434\u043e, \u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432 \u043d\u0435\u0442)<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0441\u043f\u0430\u0441\u0442\u0438, \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. <strong>\u0418 \u0442\u0443\u0442 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435.<\/strong><\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432 \u0434\u043e\u043a\u043b\u0430\u0434\u0435 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043f\u0440\u043e Django 2.2 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 PostgreSQL. \u0417\u0430 \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u043b\u0430\u0434\u0430 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b\u0448\u043b\u0430 Django 3.2 \u0441\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0433\u0440\u0430\u044e\u0442 \u0440\u043e\u043b\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u043b\u0430\u0434\u0430. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u043e\u0441\u044c \u0438 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p><em>Note: \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f NDA \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043f\u043e\u043b\u044e name, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438: <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class Person(models.Model):    name = models.CharField(max_length=100)    address = models.CharField(max_length=100)    status = models.CharField(max_length=100) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445 \u043d\u0430\u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 lookup\u2019\u044b:<\/p>\n<ul>\n<li>\n<p>__exact<\/p>\n<\/li>\n<li>\n<p>__iexact<\/p>\n<\/li>\n<li>\n<p>__contains<\/p>\n<\/li>\n<li>\n<p>__icontains<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u2014 \u043f\u0435\u0440\u0435\u0432\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 ORM \u0432 \u0441\u044b\u0440\u043e\u0439 SQL \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f. \u0414\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 1 000 000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437.\u00a0<\/p>\n<p>__exact \u043f\u043e\u0432\u0435\u043b \u0441\u0435\u0431\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0434\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__exact='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE \"names_person\".\"name\" = test <\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"331\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3fd\/72b\/db7\/3fd72bdb7e113308a97752de1eae416b.png\" data-width=\"775\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0432\u043e\u0442 __iexact \u0443\u0434\u0438\u0432\u0438\u043b. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django <a href=\"https:\/\/docs.djangoproject.com\/en\/3.1\/ref\/models\/querysets\/#iexact\" rel=\"noopener noreferrer nofollow\"><u>\u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e<\/u><\/a>, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>>>> qs.filter(first_name__iexact='\u043e\u043b\u0435\u0433') SELECT ... WHERE first_name ILIKE '%\u043e\u043b\u0435\u0433%';<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 PostgreSQL \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0438\u043d\u043e\u0439:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__iexact='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE UPPER(\"names_person\".\"name\"::text) = UPPER(test) <\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"341\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d44\/2ed\/16b\/d442ed16b2a0e780b56d2fab2a71c941.png\" data-width=\"800\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0441 __contains \u0438 __icontains: __contains \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__contains='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE \"names_person\".\"name\"::text LIKE %test% <\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"332\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cdb\/36a\/4f8\/cdb36a4f862e2ecc5be9651e79f880cc.png\" data-width=\"767\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 __icontains \u0442\u043e\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 UPPER, \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u0435\u0449\u0430\u043d\u043d\u043e\u0433\u043e ILIKE<\/p>\n<pre><code>>>> str(Person.objects.filter(name__icontains='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE UPPER(\"names_person\".\"name\"::text) LIKE UPPER(%test%) <\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"330\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/458\/fb7\/924\/458fb7924b9bb497e1e2b611ea8baba1.png\" data-width=\"769\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0442\u043e\u0433\u043e:\u00a0<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"279\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30f\/be8\/02d\/30fbe802dc7bfbceec4e396ab468cb42.png\" data-width=\"556\"\/><figcaption><\/figcaption><\/figure>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21161 &#8212; db_index=True<\/h3>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u043d\u044f\u0442\u044c \u044d\u0442\u0438\u043c \u0434\u0435\u043b\u043e\u043c <s>\u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439<\/s> DBA: \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0431\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043a\u043e\u0434\u0435<\/p>\n<\/li>\n<li>\n<p>\u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0441\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0447\u0435\u0440\u0435\u0437 Django. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u0442\u0430\u0438\u043b\u0438 db_index=True \u043d\u0430 \u043d\u0430\u0448\u0443 \u043a\u043e\u043b\u043e\u043d\u043a\u0443.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043f\u043e\u0439\u043b\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class Person(models.Model):  name = models.CharField(max_length=100, db_index=True)  address = models.CharField(max_length=100)  status = models.CharField(max_length=100) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043d\u043e\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"284\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a56\/7ca\/666\/a567ca666991c3dd2cc059c93dec1a76.png\" data-width=\"697\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 __exact. \u042d\u0442\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043a\u043e\u0434 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 Django:<\/p>\n<pre><code class=\"django\">BEGIN; -- -- Alter field name on person -- CREATE INDEX \"names_person_name_f55af680\" ON \"names_person\" (\"name\"); CREATE INDEX \"names_person_name_f55af680_like\" ON \"names_person\" (\"name\" varchar_pattern_ops); COMMIT; <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f B-Tree \u0438\u043d\u0434\u0435\u043a\u0441 (\u0442.\u043a. \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 PostgreSQl \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d), \u0430 \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f<\/p>\n<blockquote>\n<p>B-trees can handle equality and range queries on data that can be sorted into some ordering. In particular, the PostgreSQL query planner will consider using a B-tree index whenever an indexed column is involved in a comparison using one of these operators:<\/p>\n<p><strong>&lt; , &lt;= , = , >= , ><\/strong><\/p>\n<p>&lt;&#8230;><\/p>\n<p>The optimizer can also use a B-tree index for queries involving the pattern matching operators LIKE and ~ if the pattern is a constant and is anchored to the beginning of the string \u2014 for example, <strong>col LIKE &#8216;foo%&#8217; or col ~ &#8216;^foo&#8217;<\/strong>, but not col LIKE &#8216;%bar&#8217;.<\/p>\n<p><a href=\"https:\/\/www.google.com\/url?q=https:\/\/postgrespro.com\/docs\/postgresql\/9.6\/indexes-types&amp;sa=D&amp;source=docs&amp;ust=1640600914728405&amp;usg=AOvVaw3hMvEsHtfuMtSvvgMXdiX8\" rel=\"noopener noreferrer nofollow\"><em>via PostgresPro<\/em><\/a><\/p>\n<\/blockquote>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c \u0441\u043b\u043e\u0432\u0435 \u201cvarchar_pattern_ops\u201d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043d\u0430\u043c \u0435\u0449\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f. \u042d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 op_class\u00a0 \u0438\u043b\u0438 operator class. \u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0441\u043e\u0431\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0421-\u043b\u043e\u043a\u0430\u043b\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 (LIKE \u0438 ~) \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0435 \u0432 \u043b\u043e\u043a\u0430\u043b\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0443\u0442: <a href=\"https:\/\/www.postgresql.org\/docs\/9.5\/indexes-opclass.html\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.postgresql.org\/docs\/9.5\/indexes-opclass.html<\/u><\/a><\/p>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21162 \u2013 \u0441\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/h3>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438, \u043e\u0441\u043e\u0437\u043d\u0430\u0432, \u0447\u0442\u043e __iexact \u0432 \u0446\u0435\u043b\u043e\u043c \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 UPPER(\u201cname\u201d), \u043c\u044b \u043f\u043e\u0448\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Django. \u041e\u0442\u0432\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0440\u043e\u0437\u0430\u0438\u0447\u043d\u044b\u043c \u2014 \u043d\u0438\u043a\u0430\u043a. \u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Index, \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 db_index, \u043d\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043e \u043d\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u044d\u0442\u043e <a href=\"https:\/\/docs.djangoproject.com\/en\/2.2\/ref\/models\/indexes\/#index-options\" rel=\"noopener noreferrer nofollow\"><u>\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/u><\/a> 5 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0435\u0434\u043e\u043b\u0433\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0432, \u043c\u044b \u043f\u043e\u043b\u0435\u0437\u043b\u0438 \u043d\u0430 github (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c), \u043d\u0430\u0448\u043b\u0438 \u0442\u0430\u043c \u043a\u043b\u0430\u0441\u0441 Index \u0438 \u0432 \u043d\u0435\u043c \u043c\u0435\u0442\u043e\u0434 create_sql, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0434\u044f \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c SQL-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u043f\u0443\u0442\u0438 \u0434\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0434\u043e\u043a\u043b\u0430\u0434\u0435, \u0437\u0434\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0443:\u00a0<\/p>\n<ol>\n<li>\n<p>\u041f\u0438\u0448\u0435\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043e\u0442 Index, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u043c create_sql \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0447\u043a\u0443 \u0434\u0435\u0431\u0430\u0433\u0430 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u0414\u0430\u043b\u044c\u0448\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">class UpperIndex(Index):    def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )         return statement  class Person(models.Model):    name = models.CharField(max_length=100, db_index=True)    address = models.CharField(max_length=100)    status = models.CharField(max_length=100)     class Meta:        indexes = [            UpperIndex(fields=['name'],                       name='name_upper_index')        ] <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0412 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c statement \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d SQL-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044c parts, \u043a\u043b\u044e\u0447 columns \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u0430\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"368\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92f\/45e\/c06\/92f45ec06497ad37220445918478050d.png\" data-width=\"797\"\/><figcaption><\/figcaption><\/figure>\n<ol start=\"3\">\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c <a href=\"https:\/\/github.com\/django\/django\/blob\/stable\/2.2.x\/django\/db\/backends\/ddl_references.py#L76\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/u><\/a> Columns \u043d\u0430 github \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 (\u043c\u0435\u0442\u043e\u0434 __str__)  <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def __str__(self):    def col_str(column, idx):        try:            return self.quote_name(column) + self.col_suffixes[idx]        except IndexError:            return self.quote_name(column)     return ', '.join(col_str(column, idx) for idx, column in enumerate(self.columns)) <\/code><\/pre>\n<ol start=\"4\">\n<li>\n<p>\u041f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 self.quote_name \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0441\u0432\u043e\u0439 \u2014 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u043d\u0430\u043f\u0443\u0442\u0430\u0442\u044c: \u043c\u0435\u0442\u043e\u0434 quote_name \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 column, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0443 statement.parts[\u2018columns\u2019]<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">class UpperIndex(Index):    def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )        quote_name = statement.parts['columns'].quote_name         def upper_quoted(column):            return 'UPPER({0})'.format(quote_name(column))         statement.parts['columns'].quote_name = upper_quoted        return statement <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 __iexact \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"265\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a18\/135\/986\/a18135986d12683eb9f08425c5245951.png\" data-width=\"774\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"269\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d1\/cdc\/38a\/9d1cdc38ae361ada7da5360d35bc2725.png\" data-width=\"631\"\/><figcaption><\/figcaption><\/figure>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21163 \u2014 Trigram<\/h3>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 __exact \u0438 __iexact, \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043d\u0430 __contains \u0438 __icontains, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 LIKE, \u0430 \u0441 \u043d\u0438\u043c B-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442. \u041f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 PostgreSQL \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442. \u041d\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 op_classes, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u0438 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Trigram, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f GiST \u0438 Gin \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434 LIKE \u0438 ILIKE \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b.\u00a0<\/p>\n<p>\u041c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u043e\u0431\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043d\u0430 \u043f\u0440\u043e\u0434\u0435 GiST \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442, \u0430 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 1 000 000 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438) \u043f\u0440\u0438\u0440\u043e\u0441\u0442\u0430 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043d\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>Gin \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430 \u043f\u0440\u043e\u0434\u0435, \u0438 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u043a\u0435, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2014 \u043e\u043d \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u043e\u0432:\u00a0<\/p>\n<p><em>Gist __contains<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"348\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/451\/618\/1fb\/4516181fb358ee5dbe7fe06a10bd7d64.png\" data-width=\"767\"\/><figcaption><\/figcaption><\/figure>\n<p><em>Gist __icontains<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"315\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b86\/65d\/f42\/b8665df42a005fcda6f3fa3dfbb0b000.png\" data-width=\"775\"\/><figcaption><\/figcaption><\/figure>\n<p><em>Gin __contains<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"354\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f39\/a09\/1e2\/f39a091e202081ae458b4653315a7fbc.png\" data-width=\"775\"\/><figcaption><\/figcaption><\/figure>\n<p><em>Gin __icontains<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"309\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/179\/b13\/7c6\/179b137c6b80346dc4cc67da1a9db132.png\" data-width=\"769\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f (\u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u043c\u044b \u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430):<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"352\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b03\/76c\/168\/b0376c1681e2b8c20bf91d6fe4203f0e.png\" data-width=\"871\"\/><figcaption><\/figcaption><\/figure>\n<p><a class=\"anchor\" name=\"6\" id=\"6\"><\/a><\/p>\n<h2>\u041a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f?<\/h2>\n<p>\u0414\u043b\u044f __contains \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c GinIndex \u043a \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c gin_trgm_op<\/p>\n<pre><code class=\"python\">from django.contrib.postgres.indexes import GinIndex  class Person(models.Model):   name = models.CharField(max_length=100, db_index=True)   address = models.CharField(max_length=100)   status = models.CharField(max_length=100)    class Meta:       indexes = [           GinIndex(fields=['name'], name='name_gin_index', opclasses=['gin_trgm_ops'])       ] <\/code><\/pre>\n<p>\u0414\u043b\u044f __icontains \u0431\u0435\u0440\u0435\u043c \u043d\u0430\u0448 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043c\u0435\u043d\u044f\u0435\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u043d\u0430 GinIndex \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u044c gin_trgm_op<\/p>\n<pre><code class=\"python\">class UpperGistIndex(GinIndex):     def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )        quote_name = statement.parts['columns'].quote_name         def upper_quoted(column):            return 'UPPER({0})'.format(quote_name(column))         statement.parts['columns'].quote_name = upper_quoted        return statement<\/code><\/pre>\n<p><strong>\u0412\u0430\u0436\u043d\u043e <\/strong>\u0442.\u043a. Trigram \u2014 \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f PostgreSQL, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u043e \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u0438 \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0414\u041e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f\u0445 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u044b c <strong>&#8216;gin_trgm_ops&#8217; <\/strong>\u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 TrigramExtension(). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432<\/p>\n<pre><code class=\"python\">from django.contrib.postgres.operations import TrigramExtension  class Migration(migrations.Migration):    dependencies = [        ('users', '0001__initial'),    ]    operations = [        TrigramExtension(), # \u0442\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0438\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432    ] <\/code><\/pre>\n<p><a class=\"anchor\" name=\"7\" id=\"7\"><\/a><\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438<\/h3>\n<pre><code class=\"python\">class UpperIndex(Index):    def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )        quote_name = statement.parts['columns'].quote_name         def upper_quoted(column):            return 'UPPER({0})'.format(quote_name(column))         statement.parts['columns'].quote_name = upper_quoted        return statement  class UpperGinIndex(GinIndex):     def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )        quote_name = statement.parts['columns'].quote_name         def upper_quoted(column):            return 'UPPER({0})'.format(quote_name(column))         statement.parts['columns'].quote_name = upper_quoted        return statement   class Person(models.Model):  name = models.CharField(max_length=100, db_index=True)  address = models.CharField(max_length=100)  status = models.CharField(max_length=100)   class Meta:      indexes = [          UpperIndex(fields=['name'],                       name='name_upper_index'),            GinIndex(fields=['name'], name='name_gin_index', opclasses=['gin_trgm_ops']),            UpperGinIndex(fields=['name'], name='name_gin_upper_index', opclasses=['gin_trgm_ops']),      ] <\/code><\/pre>\n<p><a class=\"anchor\" name=\"8\" id=\"8\"><\/a><\/p>\n<h3>Django 3.2<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c, \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438:\u00a0 \u0432 3.2 \u0432\u0432\u0435\u043b\u0438 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 expressions \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445, \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:\u00a0<\/p>\n<pre><code class=\"python\">class Person(models.Model):  name = models.CharField(max_length=100, db_index=True)  address = models.CharField(max_length=100)  status = models.CharField(max_length=100)   class Meta:      indexes = [          Index(Upper('name'), name='name_upper_index'),            GinIndex(fields=['name'], name='name_gin_index', opclasses=['gin_trgm_ops']),            GinIndex(OpClass(Upper('name'), name='gin_trgm_ops'), name='name_upper_gin_index'),      ] <\/code><\/pre>\n<p><a class=\"anchor\" name=\"9\" id=\"9\"><\/a><\/p>\n<h3>\u0417\u0430\u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u043b\u0430\u0434\u0430<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u043b\u0430\u0434\u0430 \u043d\u0430\u043c \u043f\u043e\u0434\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0434\u0435\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0449\u0435 Hash \u0438 Rum \u0438\u043d\u0434\u0435\u043a\u0441\u044b.<\/p>\n<h4>Hash  <\/h4>\n<p>Hash \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u201c=\u201d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0441\u0438\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0443 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u043e B-Tree \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c<\/summary>\n<div class=\"spoiler__content\">\n<p>Hash \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0443 Django \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0438 \u043a\u0430\u043a \u0438 Gist \u0438 Gin \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 \u0434\u043b\u044f postgres, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a<\/p>\n<pre><code class=\"python\">from django.contrib.postgres.indexes import HashIndex from django.db import models   class Person(models.Model):   name = models.CharField(max_length=100)   address = models.CharField(max_length=100)   status = models.CharField(max_length=100)    class Meta:       indexes = [           HashIndex(fields=['name'], name='name_hash_index'),           UpperIndex(fields=['name'], name='name_upper_hash_index')       ] <\/code><\/pre>\n<\/div>\n<\/details>\n<p><em>__exact<\/em><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"310\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/db8\/51c\/822\/db851c8229ebc02d882a7ec6af8751e5.png\" data-width=\"2048\"\/><figcaption><\/figcaption><\/figure>\n<p><em>__iexact<\/em>  <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"393\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/756\/9cd\/b37\/7569cdb37fc106b83bf9de363433e799.png\" data-width=\"2048\"\/><figcaption><\/figcaption><\/figure>\n<h4>Rum  <\/h4>\n<p>\u0410 \u0432\u043e\u0442 \u0441 Rum \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0432\u0441\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435:\u00a0<\/p>\n<ol>\n<li>\n<p>Rum \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 PostgresPro Enterprise, \u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043c\u0435\u043a\u043e\u0432 \u043d\u0430 Rum \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043f\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e extension \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0418 \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: Rum \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438, \u0445\u043e\u0442\u044c \u043e\u043d \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 Gin, \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c LIKE Rum-\u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433\u0438:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"411\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b20\/b9e\/e1b\/b20b9ee1bd63925ea162af3f616390a0.png\" data-width=\"876\"\/><figcaption><\/figcaption><\/figure>\n<hr\/>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u043d\u0430\u0448 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b<a href=\"https:\/\/t.me\/technokratos\" rel=\"noopener noreferrer nofollow\"> \u00ab\u0413\u043e\u043b\u043e\u0441 \u0422\u0435\u0445\u043d\u043e\u043a\u0440\u0430\u0442\u0438\u0438\u00bb<\/a>. \u041a\u0430\u0436\u0434\u043e\u0435 \u0443\u0442\u0440\u043e \u043c\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u043d\u043e\u0439 \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442 \u0438\u0437 \u043c\u0438\u0440\u0430 \u0418\u0422, \u0430 \u043f\u043e \u0432\u0435\u0447\u0435\u0440\u0430\u043c \u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u043c\u0430\u0441\u0442\u0440\u0438\u0434\u0430\u043c\u0438.      <\/p>\n<\/div>\n<\/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\/post\/598107\/\"> https:\/\/habr.com\/ru\/post\/598107\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0430 \u0441\u044b\u0440\u043e\u043c SQL, \u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (ORM). \u041e\u043d\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b,\u00a0 \u0438 \u0441\u00a0 \u0440\u043e\u0441\u0442\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0442\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041a\u0430\u043a \u0440\u0430\u0437 \u0432 \u0445\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0430, \u0447\u0442\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Django \u0441 \u043d\u0430\u043c\u0438 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0447\u0435\u0441\u0442\u043d\u0430.<\/strong><\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u044c\u0431\u0438\u043d\u0430 \u0410\u043b\u044c\u043c\u0443\u0445\u0430\u043c\u0435\u0442\u043e\u0432\u0430, \u044f python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u0446\u0430 \u0432 \u0422\u0435\u0445\u043d\u043e\u043a\u0440\u0430\u0442\u0438\u0438. \u041e \u0432\u0432\u043e\u0434\u044f\u0449\u0435\u0439 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django \u044f <a href=\"https:\/\/www.youtube.com\/watch?v=kq-1PzEE4IQ&amp;ab_channel=%D0%92%D0%B8%D0%B4%D0%B5%D0%BE%D1%81%D0%BA%D0%BE%D0%BD%D1%84%D0%B5%D1%80%D0%B5%D0%BD%D1%86%D0%B8%D0%B9IT-People\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0430<\/u><\/a> \u043d\u0430 Pycon \u0432 \u044d\u0442\u043e\u043c \u0433\u043e\u0434\u0443. \u042d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442 \u2014 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u044f \u043c\u043e\u0435\u0433\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0437\u0430\u043d\u044f\u0442, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0438\u0434\u0435\u043e. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0430 \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0442 \u0432\u0438\u0434\u0435\u043e-\u0434\u043e\u043a\u043b\u0430\u0434\u0435, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043d\u0430\u0448\u0438 \u0437\u0440\u0438\u0442\u0435\u043b\u0438. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0434\u043e\u043a\u043b\u0430\u0434, \u0441\u043c\u0435\u043b\u043e \u043b\u0438\u0441\u0442\u0430\u0439\u0442\u0435 \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0443 \u201c\u0417\u0430\u043c\u0435\u0442\u043a\u0438 \u0441 \u0434\u043e\u043a\u043b\u0430\u0434\u0430\u201d \u0438 \u0438\u0437\u0443\u0447\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432.\u00a0<\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044f \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u043b\u0430 \u043d\u0430 Pycon, \u0442\u043e \u0432\u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/61c98de54615593b75e247ca\" data-style=\"\" id=\"61c98de54615593b75e247ca\" width=\"\"><\/div>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0445\u043e\u0447\u0443 \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u041f\u0430\u0432\u043b\u0443 \u0413\u0430\u0440\u043a\u0438\u043d\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0435\u0445\u0430\u043b\u0438.<\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435:<\/p>\n<ol>\n<li>\n<p><a href=\"#1\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/2\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#3\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21161 &#8212; db_index=True<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#4\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21162 \u2013 \u0441\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#5\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21163 \u2014 Trigram<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#6\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#7\" rel=\"noopener noreferrer nofollow\">\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#8\" rel=\"noopener noreferrer nofollow\">Django 3.2<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#9\" rel=\"noopener noreferrer nofollow\">\u0411\u043e\u043d\u0443\u0441. \u0417\u0430\u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u043b\u0430\u0434\u0430<\/a><\/p>\n<\/li>\n<\/ol>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430  <\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u2014 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0438 \u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u043b\u0438\u0448\u044c \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043f\u043e\u0438\u0441\u043a \u0431\u044b\u0441\u0442\u0440\u044b\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u0432 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 Django-\u0430\u0434\u043c\u0438\u043d\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 Django \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0430\u0434\u043c\u0438\u043d\u043a\u0438, \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0434\u043e\u043b\u0433\u043e \u0436\u0434\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441 \u043d\u0435\u0435 \u0443\u0439\u0442\u0438 (\u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0434\u043e, \u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432 \u043d\u0435\u0442)<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0441\u043f\u0430\u0441\u0442\u0438, \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. <strong>\u0418 \u0442\u0443\u0442 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435.<\/strong><\/p>\n<p>\u0412\u0430\u0436\u043d\u043e\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432 \u0434\u043e\u043a\u043b\u0430\u0434\u0435 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043f\u0440\u043e Django 2.2 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 PostgreSQL. \u0417\u0430 \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043a\u043b\u0430\u0434\u0430 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b\u0448\u043b\u0430 Django 3.2 \u0441\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0433\u0440\u0430\u044e\u0442 \u0440\u043e\u043b\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u043b\u0430\u0434\u0430. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u043e\u0441\u044c \u0438 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h3>\u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p><em>Note: \u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f NDA \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u043f\u043e\u043b\u044e name, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/em><\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438: <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class Person(models.Model):    name = models.CharField(max_length=100)    address = models.CharField(max_length=100)    status = models.CharField(max_length=100) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445 \u043d\u0430\u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 lookup\u2019\u044b:<\/p>\n<ul>\n<li>\n<p>__exact<\/p>\n<\/li>\n<li>\n<p>__iexact<\/p>\n<\/li>\n<li>\n<p>__contains<\/p>\n<\/li>\n<li>\n<p>__icontains<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u2014 \u043f\u0435\u0440\u0435\u0432\u0435\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 ORM \u0432 \u0441\u044b\u0440\u043e\u0439 SQL \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f. \u0414\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 1 000 000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437.\u00a0<\/p>\n<p>__exact \u043f\u043e\u0432\u0435\u043b \u0441\u0435\u0431\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0434\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__exact='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE \"names_person\".\"name\" = test <\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0432\u043e\u0442 __iexact \u0443\u0434\u0438\u0432\u0438\u043b. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Django <a href=\"https:\/\/docs.djangoproject.com\/en\/3.1\/ref\/models\/querysets\/#iexact\" rel=\"noopener noreferrer nofollow\"><u>\u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e<\/u><\/a>, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 SQL \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>>>> qs.filter(first_name__iexact='\u043e\u043b\u0435\u0433') SELECT ... WHERE first_name ILIKE '%\u043e\u043b\u0435\u0433%';<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 PostgreSQL \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0438\u043d\u043e\u0439:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__iexact='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE UPPER(\"names_person\".\"name\"::text) = UPPER(test) <\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0441 __contains \u0438 __icontains: __contains \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code>>>> str(Person.objects.filter(name__contains='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE \"names_person\".\"name\"::text LIKE %test% <\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 __icontains \u0442\u043e\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 UPPER, \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u0435\u0449\u0430\u043d\u043d\u043e\u0433\u043e ILIKE<\/p>\n<pre><code>>>> str(Person.objects.filter(name__icontains='test').query) SELECT \"names_person\".\"id\", \"names_person\".\"name\", \"names_person\".\"address\", \"names_person\".\"status\" FROM \"names_person\" WHERE UPPER(\"names_person\".\"name\"::text) LIKE UPPER(%test%) <\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0442\u043e\u0433\u043e:\u00a0<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21161 &#8212; db_index=True<\/h3>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u043d\u044f\u0442\u044c \u044d\u0442\u0438\u043c \u0434\u0435\u043b\u043e\u043c <s>\u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439<\/s> DBA: \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0431\u0430\u0437\u0435 \u0435\u0441\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043a\u043e\u0434\u0435<\/p>\n<\/li>\n<li>\n<p>\u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0441\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0447\u0435\u0440\u0435\u0437 Django. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u0442\u0430\u0438\u043b\u0438 db_index=True \u043d\u0430 \u043d\u0430\u0448\u0443 \u043a\u043e\u043b\u043e\u043d\u043a\u0443.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043f\u043e\u0439\u043b\u0435\u0440<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">class Person(models.Model):  name = models.CharField(max_length=100, db_index=True)  address = models.CharField(max_length=100)  status = models.CharField(max_length=100) <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043d\u043e\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 __exact. \u042d\u0442\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u043a\u043e\u0434 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 Django:<\/p>\n<pre><code class=\"django\">BEGIN; -- -- Alter field name on person -- CREATE INDEX \"names_person_name_f55af680\" ON \"names_person\" (\"name\"); CREATE INDEX \"names_person_name_f55af680_like\" ON \"names_person\" (\"name\" varchar_pattern_ops); COMMIT; <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f B-Tree \u0438\u043d\u0434\u0435\u043a\u0441 (\u0442.\u043a. \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 PostgreSQl \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d), \u0430 \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f<\/p>\n<blockquote>\n<p>B-trees can handle equality and range queries on data that can be sorted into some ordering. In particular, the PostgreSQL query planner will consider using a B-tree index whenever an indexed column is involved in a comparison using one of these operators:<\/p>\n<p><strong>&lt; , &lt;= , = , >= , ><\/strong><\/p>\n<p>&lt;&#8230;><\/p>\n<p>The optimizer can also use a B-tree index for queries involving the pattern matching operators LIKE and ~ if the pattern is a constant and is anchored to the beginning of the string \u2014 for example, <strong>col LIKE &#8216;foo%&#8217; or col ~ &#8216;^foo&#8217;<\/strong>, but not col LIKE &#8216;%bar&#8217;.<\/p>\n<p><a href=\"https:\/\/www.google.com\/url?q=https:\/\/postgrespro.com\/docs\/postgresql\/9.6\/indexes-types&amp;sa=D&amp;source=docs&amp;ust=1640600914728405&amp;usg=AOvVaw3hMvEsHtfuMtSvvgMXdiX8\" rel=\"noopener noreferrer nofollow\"><em>via PostgresPro<\/em><\/a><\/p>\n<\/blockquote>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0442\u043e\u0438\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c \u0441\u043b\u043e\u0432\u0435 \u201cvarchar_pattern_ops\u201d, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043d\u0430\u043c \u0435\u0449\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f. \u042d\u0442\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 op_class\u00a0 \u0438\u043b\u0438 operator class. \u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0441\u043e\u0431\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0421-\u043b\u043e\u043a\u0430\u043b\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 (LIKE \u0438 ~) \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0435 \u0432 \u043b\u043e\u043a\u0430\u043b\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0443\u0442: <a href=\"https:\/\/www.postgresql.org\/docs\/9.5\/indexes-opclass.html\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.postgresql.org\/docs\/9.5\/indexes-opclass.html<\/u><\/a><\/p>\n<p><a class=\"anchor\" name=\"4\" id=\"4\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21162 \u2013 \u0441\u0432\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441<\/h3>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438, \u043e\u0441\u043e\u0437\u043d\u0430\u0432, \u0447\u0442\u043e __iexact \u0432 \u0446\u0435\u043b\u043e\u043c \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u044c B-tree \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 UPPER(\u201cname\u201d), \u043c\u044b \u043f\u043e\u0448\u043b\u0438 \u0438\u0441\u043a\u0430\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Django. \u041e\u0442\u0432\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043f\u0440\u043e\u0437\u0430\u0438\u0447\u043d\u044b\u043c \u2014 \u043d\u0438\u043a\u0430\u043a. \u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Index, \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 db_index, \u043d\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043e \u043d\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u044d\u0442\u043e <a href=\"https:\/\/docs.djangoproject.com\/en\/2.2\/ref\/models\/indexes\/#index-options\" rel=\"noopener noreferrer nofollow\"><u>\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/u><\/a> 5 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0435\u0434\u043e\u043b\u0433\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0432, \u043c\u044b \u043f\u043e\u043b\u0435\u0437\u043b\u0438 \u043d\u0430 github (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c), \u043d\u0430\u0448\u043b\u0438 \u0442\u0430\u043c \u043a\u043b\u0430\u0441\u0441 Index \u0438 \u0432 \u043d\u0435\u043c \u043c\u0435\u0442\u043e\u0434 create_sql, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0434\u044f \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c SQL-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e \u043f\u0443\u0442\u0438 \u0434\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0446\u0435\u043b\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0434\u043e\u043a\u043b\u0430\u0434\u0435, \u0437\u0434\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043a\u0440\u0430\u0442\u043a\u0443\u044e \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0443:\u00a0<\/p>\n<ol>\n<li>\n<p>\u041f\u0438\u0448\u0435\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430 \u043e\u0442 Index, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432 \u043d\u0435\u043c create_sql \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0447\u043a\u0443 \u0434\u0435\u0431\u0430\u0433\u0430 \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u0414\u0430\u043b\u044c\u0448\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">class UpperIndex(Index):    def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )         return statement  class Person(models.Model):    name = models.CharField(max_length=100, db_index=True)    address = models.CharField(max_length=100)    status = models.CharField(max_length=100)     class Meta:        indexes = [            UpperIndex(fields=['name'],                       name='name_upper_index')        ] <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0412 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c statement \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d SQL-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044c parts, \u043a\u043b\u044e\u0447 columns \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043a\u0430\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ol start=\"3\">\n<li>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c <a href=\"https:\/\/github.com\/django\/django\/blob\/stable\/2.2.x\/django\/db\/backends\/ddl_references.py#L76\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/u><\/a> Columns \u043d\u0430 github \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 (\u043c\u0435\u0442\u043e\u0434 __str__)  <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def __str__(self):    def col_str(column, idx):        try:            return self.quote_name(column) + self.col_suffixes[idx]        except IndexError:            return self.quote_name(column)     return ', '.join(col_str(column, idx) for idx, column in enumerate(self.columns)) <\/code><\/pre>\n<ol start=\"4\">\n<li>\n<p>\u041f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 self.quote_name \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0441\u0432\u043e\u0439 \u2014 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u043d\u0430\u043f\u0443\u0442\u0430\u0442\u044c: \u043c\u0435\u0442\u043e\u0434 quote_name \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 column, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0443 statement.parts[\u2018columns\u2019]<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">class UpperIndex(Index):    def create_sql(self, model, schema_editor, using='', **kwargs):        statement = super().create_sql(            model, schema_editor, using, **kwargs        )        quote_name = statement.parts['columns'].quote_name         def upper_quoted(column):            return 'UPPER({0})'.format(quote_name(column))         statement.parts['columns'].quote_name = upper_quoted        return statement <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 __iexact \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><a class=\"anchor\" name=\"5\" id=\"5\"><\/a><\/p>\n<h3>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u21163 \u2014 Trigram<\/h3>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c \u0441 __exact \u0438 __iexact, \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u043d\u0430 __contains \u0438 __icontains, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 LIKE, \u0430 \u0441 \u043d\u0438\u043c B-tree \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442. \u041f\u043e\u043a\u043e\u043f\u0430\u0432\u0448\u0438\u0441\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 PostgreSQL \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442. \u041d\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 op_classes, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432\u044b\u0448\u0435, \u0438 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Trigram, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f GiST \u0438 Gin \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434 LIKE \u0438 ILIKE \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b.\u00a0<\/p>\n<p>\u041c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u043e\u0431\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:\u00a0<\/p>\n<ul>\n<li>\n<p>\u043d\u0430 \u043f\u0440\u043e\u0434\u0435 GiST \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442, \u0430 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 1 000 000 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438) \u043f\u0440\u0438\u0440\u043e\u0441\u0442\u0430 \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043d\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>Gin \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430 \u043f\u0440\u043e\u0434\u0435, \u0438 \u043d\u0430 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u043a\u0435, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2014 \u043e\u043d \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u043c<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0437\u0430\u043c\u0435\u0440\u043e\u0432:\u00a0<\/p>\n<p><em>Gist <\/em><\/p>\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-327322","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327322","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=327322"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327322\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}