{"id":286689,"date":"2017-05-22T17:15:03","date_gmt":"2017-05-22T13:15:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=286689"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2017-05-22T13:15:03","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=286689","title":{"rendered":"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 Django \u0438 PostgreSQL"},"content":{"rendered":"<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. <\/p>\n<p>  <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u044f\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 PostgreSQL, \u0447\u0435\u0440\u0435\u0437 Django \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0412 \u0441\u0442\u0430\u0442\u044c\u044f \u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0447\u0438\u0441\u0442\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442. \u043a. \u043c\u0435\u043d\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0440\u0435\u0434\u0435, \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0439 \u043a \u0431\u043e\u0435\u0432\u043e\u0439. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><strong>\u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u043c\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u0432\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435.<\/strong><\/p>\n<p>  <\/p>\n<h3 id=\"modeli-realizacii-ierarhicheskih-struktur-v-bd\">\u041c\u043e\u0434\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0432 \u0411\u0414<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c\u0438 \u0432 PostgreSQL \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 <a href=\"https:\/\/medium.com\/notes-from-a-messy-desk\/representing-trees-in-postgresql-cbcdae419022\">\u043c\u043e\u0434\u0435\u043b\u0438<\/a>:<\/p>\n<p>  <\/p>\n<ol>\n<li><strong>Adjacency model (AM)<\/strong> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c;<\/li>\n<li><a href=\"https:\/\/communities.bmc.com\/docs\/DOC-9902\"><strong>Nested Sets (NS)<\/strong><\/a> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430;<\/li>\n<li><a href=\"https:\/\/communities.bmc.com\/docs\/DOC-9902\"><strong>Materialised Path model (MP)<\/strong><\/a> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043f\u0430\u0440\u0435 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u0441\u0435\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0411\u0414 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habrahabr.ru\/post\/193166\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Django \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>AM \u2014 \u0448\u0442\u0430\u0442\u043d\u0430\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f Django \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ForeignKey;<\/li>\n<li>NS \u2014 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/github.com\/django-mptt\/django-mptt\">django-mptt<\/a>;<\/li>\n<li>MP \u2014 \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/www.postgresql.org\/docs\/9.1\/static\/ltree.html\">ltree<\/a> PostgreSQL \u0441 \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 <a href=\"https:\/\/github.com\/yyjinlong\/ltreefield\">LtreeField<\/a>;<\/li>\n<\/ol>\n<p>  <\/p>\n<h3 id=\"metodika-testirovaniya\">\u041c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 150 \u0442\u044b\u0441 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439. \u0412\u0440\u0435\u043c\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0434\u043b\u044f<br \/>  \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0427\u0442\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430<\/li>\n<li>\u0427\u0442\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430<\/li>\n<li>\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0443\u0437\u043b\u0430<\/li>\n<li>\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438<\/li>\n<\/ol>\n<p>  <\/p>\n<p><em>\u0412\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/em> \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f 1000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0443\u043d\u043a\u0442\u0443, \u043a \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>  <\/p>\n<h3 id=\"apparatnoe-obespechenie-testovogo-stenda\">\u0410\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043d\u0434\u0430<\/h3>\n<p>  <\/p>\n<ul>\n<li>CPU Core i5 2,5 GHz<\/li>\n<li>RAM 1600 MHz DDR3<\/li>\n<li>SSD Samsung 850 EVO 500GB <\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"programmnoe-obespechenie-testovogo-stenda\">\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043d\u0434\u0430<\/h3>\n<p>  <\/p>\n<ul>\n<li>Python 2.7<\/li>\n<li>Postgres 9.6<\/li>\n<li>Django 1.8<\/li>\n<li>psycopg2<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"opisanie-instrumenta-testirovaniya\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043e <a href=\"https:\/\/github.com\/kuznetsovin\/sql-tree-perfomance\">\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 Django<\/a> \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0412 \u043d\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043f\u043e 3 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435. \u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>load_tree<\/code> \u2014 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430 <\/li>\n<li><code>analize<\/code> \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0431\u043e\u0440 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<p>  <\/p>\n<pre><code>python manage.py migrate python manage.py load_tree &lt;\u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438&gt; python manage.py load_tree analize &lt;\u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>analize<\/code> \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 <em>report<\/em>.<\/p>\n<p>  <\/p>\n<h3 id=\"rezultaty\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434, \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0437\u0430\u043b\u044c\u0442\u0430\u0442\u044b. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435 \u0432\u0432\u043e\u0434\u0438\u043b\u0438 \u0432\u0430\u0441 \u0432 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435, \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 \u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><em>Raw<\/em> \u2014 adjacency model<\/li>\n<li><em>Mptt<\/em> \u2014 nested sets<\/li>\n<li><em>Ltree<\/em> \u2014 materialised path<\/li>\n<\/ul>\n<p>  <\/p>\n<h4 id=\"chtenie-vsego-dereva\">\u0427\u0442\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430<\/h4>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuznetsovin.github.io\/resource\/sql_tree_perform_files\/read_tree_chart.png\" alt=\"read_tree_chart\"\/><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u0445\u0443\u0434\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0442\u0443\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c <em>Mptt<\/em>, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043e\u0434\u043d\u043e \u0443\u0440\u043e\u0432\u043d\u0435, \u0445\u043e\u0442\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c <em>Raw<\/em> \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435. <\/p>\n<p>  <\/p>\n<h4 id=\"chtenie-proizvolnogo-uzla\">\u0427\u0442\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430<\/h4>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuznetsovin.github.io\/resource\/sql_tree_perform_files\/read_node_chart.png\" alt=\"read_node_chart\"\/><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0442\u0435\u0441\u0442\u0435, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430, \u043c\u043e\u0434\u0435\u043b\u044c <em>Mptt<\/em> \u0441\u0440\u0430\u0432\u043d\u044f\u043b\u0430\u0441\u044c \u043f\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0430 \u0432\u043e\u0442 <em>Ltree<\/em> \u043d\u0430\u043f\u0440\u043e\u0442\u0438\u0432 \u0443\u0445\u0443\u0434\u0448\u0438\u043b \u0441\u0432\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u041d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 <em>Raw<\/em> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 (WITH RECURSION), \u0438, \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u044d\u0442\u043e, \u043e\u043d \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u0441\u0435\u0445. <\/p>\n<p>  <\/p>\n<h4 id=\"vstavka-uzla\">\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0443\u0437\u043b\u0430<\/h4>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuznetsovin.github.io\/resource\/sql_tree_perform_files\/insert_node_chart.png\" alt=\"insert_node_chart\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0443\u0437\u043b\u0430 \u043e\u043f\u044f\u0442\u044c \u043e\u0442\u0441\u0442\u0430\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c <em>Ltree<\/em>, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 \u043f\u0443\u0442\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u0435\u0440\u0435\u0432\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u043e \u0438\u0437 id \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c 2 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (insert, \u0430 \u043f\u043e\u0442\u043e\u043c update \u043f\u043e\u043b\u044f path), \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<h4 id=\"peremeschenie-poddereva-mezhdu-urovnyami\">\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438<\/h4>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuznetsovin.github.io\/resource\/sql_tree_perform_files\/move_node_chart.png\" alt=\"move_node_chart\"\/><\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0443\u0437\u043b\u0430 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u043e\u043c <em>Mptt<\/em> \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0445\u0443\u0434\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0441 \u0442\u0435\u043c \u0447\u0442\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0443 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u044b\u0445 \u0443\u0437\u043b\u043e\u0432, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 <em>Raw<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u043e\u0439 \u0431\u044b\u0441\u0442\u0440\u043e\u0439, \u0442. \u043a., \u043f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f. <em>Ltree<\/em> \u043d\u0435 \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0441\u0442\u0430\u043b \u043e\u0442 \u043b\u0438\u0434\u0435\u0440\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0443\u0442\u0438 \u0443 \u0432\u0441\u0435\u0445 \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u043e\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u0430. <\/p>\n<p>  <\/p>\n<h3 id=\"itogi\">\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u0447\u0442\u0430\u0432 <a href=\"https:\/\/habrahabr.ru\/post\/46659\/\">\u0441\u0440\u0430\u0432\u0435\u043d\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/a> \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0443\u0442\u043a\u0442\u0443\u0440 \u044f \u043e\u0436\u0438\u0434\u0430\u043b, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <strong>MP<\/strong>(Ltree), \u043d\u043e, \u043a \u043c\u043e\u0435\u043c\u0443 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u044e, \u043e\u043d\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u043b\u0438\u0448\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0443\u0441\u0442\u0443\u043f\u0438\u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 <strong>AM<\/strong>(Raw). \u041d\u0443 \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 <strong>NS<\/strong>(Mptt) \u0434\u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c 3-\u0435 \u043c\u0435\u0441\u0442\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 2 \u0442\u0435\u0441\u0442\u0430\u0445 \u0438\u0437 4 \u043e\u043d \u043f\u0440\u043e\u0438\u0433\u0440\u0430\u043b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0442\u0440\u044b\u0432\u043e\u043c \u043e\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u0421\u0432\u043e\u0434\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<table>\n<thead>\n<tr>\n<th>model<\/th>\n<th>insert_node<\/th>\n<th>move_node<\/th>\n<th>read_node<\/th>\n<th>read_tree<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><em>Ltree<\/em><\/td>\n<td>0.001955<\/td>\n<td>0.010375<\/td>\n<td>0.008745<\/td>\n<td>0.025522<\/td>\n<\/tr>\n<tr>\n<td><em>Mptt<\/em><\/td>\n<td>0.001006<\/td>\n<td>0.855293<\/td>\n<td>0.00104<\/td>\n<td>0.115597<\/td>\n<\/tr>\n<tr>\n<td><em>Raw<\/em><\/td>\n<td>0.001002<\/td>\n<td>0.001<\/td>\n<td>0.001012<\/td>\n<td>0.021957<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>  <\/p>\n<p><em>\u0422\u0430\u043a \u0436\u0435 \u043d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0437\u043d\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/em><\/p>\n<p>  <\/p>\n<h3 id=\"ispolzuemye-stati\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438:<\/h3>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/medium.com\/notes-from-a-messy-desk\/representing-trees-in-postgresql-cbcdae419022\">Representing Trees in PostgreSQL<\/a><\/li>\n<li><a href=\"https:\/\/communities.bmc.com\/docs\/DOC-9902\">Trees in SQL: Nested Sets and Materialized Path<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/193166\/\">\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/kuznetsovin\/sql-tree-perfomance\">Benchmark tree structure for Django<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/46659\/\">\u0418\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 Doctrine<\/a><\/li>\n<li><a href=\"https:\/\/www.postgresql.org\/docs\/9.1\/static\/ltree.html\">Ltree<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/django-mptt\/django-mptt\">Django-mptt<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/yyjinlong\/ltreefield\">LtreeFiled<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<blockquote><p>P.S. \u042d\u0442\u043e \u043a\u0440\u043e\u0441\u0441-\u043f\u043e\u0441\u0442 <a href=\"https:\/\/kuznetsovin.github.io\/post\/sql-tree-perform\/\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u0441 \u043c\u043e\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430<\/p><\/blockquote>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/329204\/\"> https:\/\/habrahabr.ru\/post\/329204\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. <\/p>\n<p>  <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u044f\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 PostgreSQL, \u0447\u0435\u0440\u0435\u0437 Django \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0412 \u0441\u0442\u0430\u0442\u044c\u044f \u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0447\u0438\u0441\u0442\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442. \u043a. \u043c\u0435\u043d\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0440\u0435\u0434\u0435, \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u043e\u0439 \u043a \u0431\u043e\u0435\u0432\u043e\u0439. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-286689","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286689","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=286689"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286689\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}