{"id":375132,"date":"2024-05-21T06:16:56","date_gmt":"2024-05-21T06:16:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=375132"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=375132","title":{"rendered":"<span>\u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0435 + PostgreSQL<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<details class=\"spoiler\">\n<summary>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0441\u0442\u0430\u0442\u0435\u0439 <a href=\"https:\/\/habr.com\/ru\/articles\/810687\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u044c 1<\/a> \u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/810855\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u044c 2<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u0435\u0435 \u0447\u0430\u0441\u0442\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 MySQL \u0438 SQLite<\/p>\n<\/div>\n<\/details>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 PostgreSQL<\/h4>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044e \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 PostgreSQL.<br \/>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0432 PostgreSQL 15.6 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<blockquote>\n<p>ERROR: \u0432\u00a0\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u00ablevels\u00bb \u0441\u0442\u043e\u043b\u0431\u0435\u0446 4\u00a0\u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <code>character(2000)<\/code> \u0432\u00a0\u043d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043d\u043e\u00a0\u0432\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0438\u043f <code>bpchar<\/code> <br \/>LINE 23: <code>cast(parent_node_id as char(2000)) as parents,<\/code> <br \/>                 ^<br \/>HINT: \u041f\u0440\u0438\u0432\u0435\u0434\u0438\u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u00a0\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443. <\/p>\n<\/blockquote>\n<p>\u042d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0434\u043b\u044f \u043c\u0435\u043d\u044f) &#8212; <code>\"bpchar\"<\/code> \u044d\u0442\u043e <code>\"blank-padded char\"<\/code>, \u043f\u043e \u0438\u0434\u0435\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 <code>char(\u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0434\u043b\u0438\u043d\u044b)<\/code>. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043f\u043e\u0440\u0438\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u044e \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e <code>char()<\/code> \u043d\u0430 <code>varchar<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u0447\u0430\u0441\u0442\u0438 2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_directory_id as parent_node_id, name as node_name from Files ),  RootNodes as ( select node_id as root_node_id from Mapping where -- Exactly one line below should be uncommented -- parent_node_id is null-- Uncomment to build from root(s) node_id in (3, 10, 17)-- Uncomment to add node_id(s) into the brackets ),  Levels as ( select node_id, parent_node_id, node_name, cast(parent_node_id as varchar) as parents, cast(node_name as varchar) as full_path, 0 as node_level from Mapping inner join RootNodes on node_id = root_node_id  union  select  Mapping.node_id,  Mapping.parent_node_id, Mapping.node_name, concat(coalesce(concat(prev.parents, '-'), ''), cast(Mapping.parent_node_id as varchar)), concat_ws(' ', prev.full_path, Mapping.node_name), prev.node_level + 1 from  Levels as prev inner join Mapping on Mapping.parent_node_id = prev.node_id ),  Branches as ( select node_id, parent_node_id, node_name, parents, full_path, node_level, case when root_node_id is null then case when node_id = last_value(node_id) over WindowByParents then '\u2514\u2500\u2500 ' else '\u251c\u2500\u2500 ' end else '' end as node_branch, case when root_node_id is null then case when node_id = last_value(node_id) over WindowByParents then '    ' else '\u2502   ' end else '' end as branch_through from Levels left join RootNodes on node_id = root_node_id window WindowByParents as ( partition by parents order by node_name rows between current row and unbounded following ) order by full_path ),  Tree as ( select node_id, parent_node_id, node_name, parents, full_path, node_level, node_branch, cast(branch_through as varchar) as all_through from Branches inner join RootNodes on node_id = root_node_id  union  select  Branches.node_id, Branches.parent_node_id, Branches.node_name, Branches.parents, Branches.full_path, Branches.node_level, Branches.node_branch, concat(prev.all_through, Branches.branch_through) from  Tree as prev inner join Branches on Branches.parent_node_id = prev.node_id ),  FineTree as ( select tr.node_id, tr.parent_node_id, tr.node_name, tr.parents, tr.full_path, tr.node_level, concat(coalesce(parent.all_through, ''), tr.node_branch, tr.node_name) as fine_tree from Tree as tr left join Tree as parent on parent.node_id = tr.parent_node_id order by tr.full_path )  select fine_tree, node_id from FineTree ;<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0433\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c\u0438:<\/p>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7bc\/8c4\/582\/7bc8c4582675e7326967b476b508006d.png\" width=\"439\" height=\"361\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7bc\/8c4\/582\/7bc8c4582675e7326967b476b508006d.png\"\/><\/figure>\n<p><em>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <\/em><code>varchar<\/code><em> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043d\u0435\u0441\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 &#8212; \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, &#171;\u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e&#187; \u043f\u043e\u043b\u0435 <\/em><code>full_path<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0435\u0435 \u0440\u0430\u0437\u0434\u043e\u0431\u044b\u0442\u044c.<\/p>\n<p><em>\u041d\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 SQLite (\u0432 \u043d\u0435\u043c \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b, \u043f\u043e\u0445\u043e\u0436\u0435, \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b), \u043d\u043e \u043d\u0435 \u0432 MySQL, \u0432 \u043d\u0435\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <\/em><code>CAST()<\/code><em>:<\/em><\/p>\n<blockquote>\n<p>Error occurred during SQL query execution<\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430:<br \/> SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#8216;varchar)) as parents,<code>cast(node_name as char(2000)) as full_path, <br \/>0 as nod' at line 23 <\/code><\/p>\n<\/blockquote>\n<h2>\u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f (80 000+ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432)<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u044c \u043e\u0431\u044a\u0435\u043c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e&#187;. <br \/>\u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0438 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0423\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 zip-\u0430\u0440\u0445\u0438\u0432\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 Git&#8217;\u0430 &#8212; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/openjdk\/jdk\" rel=\"noopener noreferrer nofollow\">OpenJDK<\/a> (83499 \u043f\u0430\u043f\u043e\u043a \u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u0438 22). <\/p>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/139\/d18\/237\/139d18237f06956de1c98869062237ef.png\" width=\"406\" height=\"324\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/139\/d18\/237\/139d18237f06956de1c98869062237ef.png\"\/><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0432, \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043c\u0435\u043d\u044e \u0432\u044b\u0431\u0440\u0430\u0442\u044c <a href=\"https:\/\/github.com\/openjdk\/jdk\/archive\/refs\/heads\/master.zip\" rel=\"noopener noreferrer nofollow\">Download ZIP<\/a> (\u043e\u0431\u044a\u0435\u043c \u0430\u0440\u0445\u0438\u0432\u0430 181 \u041c\u0411)<\/p>\n<h3>gen_table()<\/h3>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 SQL-\u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0432 \u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u043a \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0430\u0440\u0445\u0438\u0432\u0430 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e gen_table() \u043d\u0430 Python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># # Generate SQL-script for creation of hierarchical table by zip-archive structure # from zipfile import ZipFile from itertools import count   def file_size_b(file_size):     \"\"\" Returns file size string in XBytes \"\"\"     for b in [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"]:         if file_size &lt; 1024:             break         file_size \/= 1024     return f\"{round(file_size)} {b}\"   def gen_table(zip_file, table_name='ZipArchive', chunk_size=10000, out_extension='sql'):     \"\"\"     by iqu 2024-04-28     params:         zip_file - zip archive full path         table_name - table to be created         chunk_size - limit values() for each insert into part         out extension - replaces zip archive file extension     ->  None, creates file with SQL script.         Create table columns:         id, name, parent_id, file_size - obvious,         bytes - string with file size generated by file_size_b()     \"\"\"     def gen_create_table(file):         print(f\"drop table if exists {table_name};\", file=file)         print(f\"create table {table_name} (id int, name varchar(255), parent_id int, file_size int, bytes varchar(16))\"               , file=file)      def gen_insert(file):         print(f\";\\ninsert into {table_name} (id, name, parent_id, file_size, bytes) values\", file=file)      out_file = \".\".join(zip_file.split(\".\")[:-1] + [out_extension])      cnt = count()     parents = ['NULL']      with open(out_file, mode='w') as of:         gen_create_table(of)          with ZipFile(zip_file) as zf:             for zi in zf.infolist():                 zi_id = cnt.__next__()                 if zi_id % chunk_size == 0:                     gen_insert(of)                     delimiter = ''                 else:                     delimiter = ','                  level = zi.filename.count(\"\/\") - zi.is_dir()                 name = zi.filename.split(\"\/\")[level]                 file_size = -1 if zi.is_dir() else zi.file_size                 file_size_s = 'DIR' if zi.is_dir() else file_size_b(zi.file_size)                 if zi.is_dir():                     if len(parents) &lt; level + 2:                         parents.append(f\"{zi_id}\")                     else:                         parents[level + 1] = f\"{zi_id}\"                  print(f\"{delimiter}({zi_id}, '{name}', {parents[level]}, {file_size}, '{file_size_s}')\", file=of)             print(';', file=of)   gen_table(r\"C:\\TEMP\\jdk-master.zip\")    # Sample archive https:\/\/github.com\/openjdk\/jdk\/archive\/refs\/heads\/master.zip <\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u043d\u0435 \u0431\u0443\u0434\u0443, \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043f\u043e \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u0441\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c <code>chunk_size<\/code> (10 000 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435 <code>values()<\/code><\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0418\u0414, \u0438\u043c\u0435\u043d\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u0430\u0436\u0434\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u0435 <code>file_size<\/code> \u0441 \u0434\u043b\u0438\u043d\u043e\u0439 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445 (-1 \u0434\u043b\u044f \u043f\u0430\u043f\u043e\u043a) \u0438 \u043f\u043e\u043b\u0435 <code>bytes<\/code> \u0441 \u0434\u043b\u0438\u043d\u043e\u0439, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445, \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442\u0430\u0445 \u0438 \u0442.\u0434. (<code>'DIR'<\/code> \u0434\u043b\u044f \u043f\u0430\u043f\u043e\u043a)<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435 \u0430\u0440\u0445\u0438\u0432\u0443, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b SQL-\u0441\u043a\u0440\u0438\u043f\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438. <em>\u041f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0443, \u0435\u0433\u043e \u0430\u0440\u0445\u0438\u0432 &#171;\u0432\u0435\u0441\u0438\u0442&#187; \u043f\u043e\u0447\u0442\u0438 1\u041c\u0411, \u0441\u043f\u043e\u0441\u043e\u0431 \u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d<\/em><\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 9 \u0447\u0430\u0441\u0442\u0435\u0439. \u041e\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0445 &#171;\u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u044b\u0445&#187; \u0421\u0423\u0411\u0414. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c.<\/p>\n<h3>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432 MySQL, SQLite \u0438 PostgreSQL<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 MySQL \u0438 SQLite \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0434\u043b\u044f PostgreSQL &#8212; \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0430 \u0441\u0432\u043e\u0435\u043c \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u043c \u041f\u041a \u043f\u043e\u0434 Windows 10. \u0412\u0441\u0435 \u0421\u0423\u0411\u0414 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 C:\\, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u043c\u0441\u044f \u043d\u0430 SSD, \u0444\u0430\u0439\u043b\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 \u043d\u0435\u043c \u0436\u0435. \u0412\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0421\u0423\u0411\u0414 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. <\/p>\n<p>\u0412\u0441\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438\u0437 DBeaver 24.0.2, \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043e &#8212; \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0421\u0423\u0411\u0414 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u044e, \u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 \u0438\u0445 \u0441\u0440\u0435\u0434\u0430\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u043f\u0440\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a \u0438\u043c\u0435\u043d\u0438 \u0443\u0437\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445, \u0430 \u0438\u0437 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e CTE \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0437\u043b\u0430 \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438:<\/p>\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_id as parent_node_id, concat(name, ' (', bytes, ')')as node_name from ZipArchive ),  ...  select fine_tree, node_id, node_level from FineTree ;<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0436\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430), \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0443\u043c\u043c\u0443 \u0434\u043b\u0438\u043d \u043f\u043e\u043b\u044f <code>full_path<\/code> \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432, \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"sql\">... select sum(length(full_path)), max(length(full_path)) from FineTree ;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>\u0421\u043a\u0440\u0438\u043f\u0442<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>MySQL 8.2<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>SQLite 3<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>PostgreSQL 15.6<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>jdk-master.sql<\/code> (\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b &#8212; \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430)<\/p>\n<\/td>\n<td>\n<p align=\"left\">1800 ms<\/p>\n<\/td>\n<td>\n<p align=\"left\">200 ms<\/p>\n<\/td>\n<td>\n<p align=\"left\">500 ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 s<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 s<\/p>\n<\/td>\n<td>\n<p align=\"left\">3 s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<p align=\"left\">sum(length(full_path))<\/p>\n<p align=\"left\">max(length(full_path))<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">1 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">3 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u0443\u044e \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/p>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ed0\/dad\/8d8\/ed0dad8d876ab1351aa71c4e6750f93b.png\" width=\"368\" height=\"273\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ed0\/dad\/8d8\/ed0dad8d876ab1351aa71c4e6750f93b.png\"\/><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f SQLite<\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 &#8212; 16<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0421\u0423\u0411\u0414 &#8212; \u0434\u043b\u044f SQLite \u043e\u043d \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439, \u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 MySQL \u0438 PostgreSQL \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/11f\/f0b\/168\/11ff0b1680b4cc19b7c5dd007967e29f.png\" alt=\"PostgreSQL\" title=\"PostgreSQL\" width=\"1100\" height=\"616\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/11f\/f0b\/168\/11ff0b1680b4cc19b7c5dd007967e29f.png\"\/><\/p>\n<div><figcaption>PostgreSQL<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42b\/c6b\/712\/42bc6b712a77a063e46245428c16bc1d.png\" alt=\"MySQL\" title=\"MySQL\" width=\"1095\" height=\"617\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42b\/c6b\/712\/42bc6b712a77a063e46245428c16bc1d.png\"\/><\/p>\n<div><figcaption>MySQL<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u044d\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0421\u0423\u0411\u0414 \u0432\u044b\u0432\u043e\u0434 \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0421\u0423\u0411\u0414 \u0441\u043e\u0432\u043f\u0430\u043b\u0438, \u0434\u0430\u0436\u0435 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL \u0438 PostgreSQL. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u043e\u043b\u044f <code>full_path<\/code> \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 255, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e &#171;\u0441\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u043d\u0438\u044f&#187; \u0441 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f PostgreSQL \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>varchar<\/code> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b, \u043e\u0431\u0440\u0435\u0437\u043a\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u044d\u0442\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f SQLite.<\/p>\n<p><strong>\u0412 \u0446\u0435\u043b\u043e\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0446\u0435\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0442\u0440\u0435\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0421\u0423\u0411\u0414.<\/strong><\/p>\n<p>\u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043a\u0430\u043a\u0438\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0438 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043b\u0438 \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u043a\u043e\u043d\u0447\u0435\u043d, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0437\u0430 \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 &#8212; \u043e\u043d \u0441\u0442\u0430\u043b \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043d\u0435\u0442 )))<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/811523\/\"> https:\/\/habr.com\/ru\/articles\/811523\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<details class=\"spoiler\">\n<summary>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0441\u0442\u0430\u0442\u0435\u0439 <a href=\"https:\/\/habr.com\/ru\/articles\/810687\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u044c 1<\/a> \u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/810855\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u044c 2<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u0435\u0435 \u0447\u0430\u0441\u0442\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 MySQL \u0438 SQLite<\/p>\n<\/div>\n<\/details>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 PostgreSQL<\/h4>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044e \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432 PostgreSQL.<br \/>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0432 PostgreSQL 15.6 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<blockquote>\n<p>ERROR: \u0432\u00a0\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u00ablevels\u00bb \u0441\u0442\u043e\u043b\u0431\u0435\u0446 4\u00a0\u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <code>character(2000)<\/code> \u0432\u00a0\u043d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043d\u043e\u00a0\u0432\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0438\u043f <code>bpchar<\/code> <br \/>LINE 23: <code>cast(parent_node_id as char(2000)) as parents,<\/code> <br \/>                 ^<br \/>HINT: \u041f\u0440\u0438\u0432\u0435\u0434\u0438\u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u00a0\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443. <\/p>\n<\/blockquote>\n<p>\u042d\u0442\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0434\u043b\u044f \u043c\u0435\u043d\u044f) &#8212; <code>\"bpchar\"<\/code> \u044d\u0442\u043e <code>\"blank-padded char\"<\/code>, \u043f\u043e \u0438\u0434\u0435\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 <code>char(\u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0434\u043b\u0438\u043d\u044b)<\/code>. \u041d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043f\u043e\u0440\u0438\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u044e \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e <code>char()<\/code> \u043d\u0430 <code>varchar<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u0447\u0430\u0441\u0442\u0438 2<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_directory_id as parent_node_id, name as node_name from Files ),  RootNodes as ( select node_id as root_node_id from Mapping where -- Exactly one line below should be uncommented -- parent_node_id is null-- Uncomment to build from root(s) node_id in (3, 10, 17)-- Uncomment to add node_id(s) into the brackets ),  Levels as ( select node_id, parent_node_id, node_name, cast(parent_node_id as varchar) as parents, cast(node_name as varchar) as full_path, 0 as node_level from Mapping inner join RootNodes on node_id = root_node_id  union  select  Mapping.node_id,  Mapping.parent_node_id, Mapping.node_name, concat(coalesce(concat(prev.parents, '-'), ''), cast(Mapping.parent_node_id as varchar)), concat_ws(' ', prev.full_path, Mapping.node_name), prev.node_level + 1 from  Levels as prev inner join Mapping on Mapping.parent_node_id = prev.node_id ),  Branches as ( select node_id, parent_node_id, node_name, parents, full_path, node_level, case when root_node_id is null then case when node_id = last_value(node_id) over WindowByParents then '\u2514\u2500\u2500 ' else '\u251c\u2500\u2500 ' end else '' end as node_branch, case when root_node_id is null then case when node_id = last_value(node_id) over WindowByParents then '    ' else '\u2502   ' end else '' end as branch_through from Levels left join RootNodes on node_id = root_node_id window WindowByParents as ( partition by parents order by node_name rows between current row and unbounded following ) order by full_path ),  Tree as ( select node_id, parent_node_id, node_name, parents, full_path, node_level, node_branch, cast(branch_through as varchar) as all_through from Branches inner join RootNodes on node_id = root_node_id  union  select  Branches.node_id, Branches.parent_node_id, Branches.node_name, Branches.parents, Branches.full_path, Branches.node_level, Branches.node_branch, concat(prev.all_through, Branches.branch_through) from  Tree as prev inner join Branches on Branches.parent_node_id = prev.node_id ),  FineTree as ( select tr.node_id, tr.parent_node_id, tr.node_name, tr.parents, tr.full_path, tr.node_level, concat(coalesce(parent.all_through, ''), tr.node_branch, tr.node_name) as fine_tree from Tree as tr left join Tree as parent on parent.node_id = tr.parent_node_id order by tr.full_path )  select fine_tree, node_id from FineTree ;<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0433\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c\u0438:<\/p>\n<figure class=\"float\"><\/figure>\n<p><em>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <\/em><code>varchar<\/code><em> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043d\u0435\u0441\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u043b\u044c \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0439 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 &#8212; \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, &#171;\u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e&#187; \u043f\u043e\u043b\u0435 <\/em><code>full_path<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0435\u0435 \u0440\u0430\u0437\u0434\u043e\u0431\u044b\u0442\u044c.<\/p>\n<p><em>\u041d\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 SQLite (\u0432 \u043d\u0435\u043c \u0432\u0441\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b, \u043f\u043e\u0445\u043e\u0436\u0435, \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b), \u043d\u043e \u043d\u0435 \u0432 MySQL, \u0432 \u043d\u0435\u043c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <\/em><code>CAST()<\/code><em>:<\/em><\/p>\n<blockquote>\n<p>Error occurred during SQL query execution<\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430:<br \/> SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#8216;varchar)) as parents,<code>cast(node_name as char(2000)) as full_path, <br \/>0 as nod' at line 23 <\/code><\/p>\n<\/blockquote>\n<h2>\u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f (80 000+ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432)<\/h2>\n<p>\u041d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u043c\u0443 &#171;\u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u044c \u043e\u0431\u044a\u0435\u043c\u043d\u0443\u044e \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044e&#187;. <br \/>\u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0438 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0423\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 zip-\u0430\u0440\u0445\u0438\u0432\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 Git&#8217;\u0430 &#8212; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/openjdk\/jdk\" rel=\"noopener noreferrer nofollow\">OpenJDK<\/a> (83499 \u043f\u0430\u043f\u043e\u043a \u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u044e \u0432\u0435\u0440\u0441\u0438\u0438 22). <\/p>\n<figure class=\"float\"><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0432, \u043d\u0443\u0436\u043d\u043e \u0438\u0437 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043c\u0435\u043d\u044e \u0432\u044b\u0431\u0440\u0430\u0442\u044c <a href=\"https:\/\/github.com\/openjdk\/jdk\/archive\/refs\/heads\/master.zip\" rel=\"noopener noreferrer nofollow\">Download ZIP<\/a> (\u043e\u0431\u044a\u0435\u043c \u0430\u0440\u0445\u0438\u0432\u0430 181 \u041c\u0411)<\/p>\n<h3>gen_table()<\/h3>\n<details class=\"spoiler\">\n<summary>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 SQL-\u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0432 \u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u043a \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0430\u0440\u0445\u0438\u0432\u0430 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e gen_table() \u043d\u0430 Python<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># # Generate SQL-script for creation of hierarchical table by zip-archive structure # from zipfile import ZipFile from itertools import count   def file_size_b(file_size):     \"\"\" Returns file size string in XBytes \"\"\"     for b in [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"]:         if file_size &lt; 1024:             break         file_size \/= 1024     return f\"{round(file_size)} {b}\"   def gen_table(zip_file, table_name='ZipArchive', chunk_size=10000, out_extension='sql'):     \"\"\"     by iqu 2024-04-28     params:         zip_file - zip archive full path         table_name - table to be created         chunk_size - limit values() for each insert into part         out extension - replaces zip archive file extension     ->  None, creates file with SQL script.         Create table columns:         id, name, parent_id, file_size - obvious,         bytes - string with file size generated by file_size_b()     \"\"\"     def gen_create_table(file):         print(f\"drop table if exists {table_name};\", file=file)         print(f\"create table {table_name} (id int, name varchar(255), parent_id int, file_size int, bytes varchar(16))\"               , file=file)      def gen_insert(file):         print(f\";\\ninsert into {table_name} (id, name, parent_id, file_size, bytes) values\", file=file)      out_file = \".\".join(zip_file.split(\".\")[:-1] + [out_extension])      cnt = count()     parents = ['NULL']      with open(out_file, mode='w') as of:         gen_create_table(of)          with ZipFile(zip_file) as zf:             for zi in zf.infolist():                 zi_id = cnt.__next__()                 if zi_id % chunk_size == 0:                     gen_insert(of)                     delimiter = ''                 else:                     delimiter = ','                  level = zi.filename.count(\"\/\") - zi.is_dir()                 name = zi.filename.split(\"\/\")[level]                 file_size = -1 if zi.is_dir() else zi.file_size                 file_size_s = 'DIR' if zi.is_dir() else file_size_b(zi.file_size)                 if zi.is_dir():                     if len(parents) &lt; level + 2:                         parents.append(f\"{zi_id}\")                     else:                         parents[level + 1] = f\"{zi_id}\"                  print(f\"{delimiter}({zi_id}, '{name}', {parents[level]}, {file_size}, '{file_size_s}')\", file=of)             print(';', file=of)   gen_table(r\"C:\\TEMP\\jdk-master.zip\")    # Sample archive https:\/\/github.com\/openjdk\/jdk\/archive\/refs\/heads\/master.zip <\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u043d\u0435 \u0431\u0443\u0434\u0443, \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043f\u043e \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u0441\u043a\u0440\u0438\u043f\u0442 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c <code>chunk_size<\/code> (10 000 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e) \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u043b\u043e\u043a\u0435 <code>values()<\/code><\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0418\u0414, \u0438\u043c\u0435\u043d\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f, \u043a\u0430\u0436\u0434\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u0435 <code>file_size<\/code> \u0441 \u0434\u043b\u0438\u043d\u043e\u0439 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445 (-1 \u0434\u043b\u044f \u043f\u0430\u043f\u043e\u043a) \u0438 \u043f\u043e\u043b\u0435 <code>bytes<\/code> \u0441 \u0434\u043b\u0438\u043d\u043e\u0439, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043a \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445, \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442\u0430\u0445 \u0438 \u0442.\u0434. (<code>'DIR'<\/code> \u0434\u043b\u044f \u043f\u0430\u043f\u043e\u043a)<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0448\u0435 \u0430\u0440\u0445\u0438\u0432\u0443, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b SQL-\u0441\u043a\u0440\u0438\u043f\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438. <em>\u041f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u0431\u0443\u0434\u0443, \u0435\u0433\u043e \u0430\u0440\u0445\u0438\u0432 &#171;\u0432\u0435\u0441\u0438\u0442&#187; \u043f\u043e\u0447\u0442\u0438 1\u041c\u0411, \u0441\u043f\u043e\u0441\u043e\u0431 \u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d<\/em><\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 9 \u0447\u0430\u0441\u0442\u0435\u0439. \u041e\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0445 &#171;\u043f\u043e\u0434\u043e\u043f\u044b\u0442\u043d\u044b\u0445&#187; \u0421\u0423\u0411\u0414. \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c.<\/p>\n<h3>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432 MySQL, SQLite \u0438 PostgreSQL<\/h3>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 MySQL \u0438 SQLite \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438\u0437 \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0434\u043b\u044f PostgreSQL &#8212; \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043d\u0430 \u0441\u0432\u043e\u0435\u043c \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u043c \u041f\u041a \u043f\u043e\u0434 Windows 10. \u0412\u0441\u0435 \u0421\u0423\u0411\u0414 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 C:\\, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0435\u043c\u0441\u044f \u043d\u0430 SSD, \u0444\u0430\u0439\u043b\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 \u043d\u0435\u043c \u0436\u0435. \u0412\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u0421\u0423\u0411\u0414 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. <\/p>\n<p>\u0412\u0441\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0438\u0437 DBeaver 24.0.2, \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u043e &#8212; \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0421\u0423\u0411\u0414 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u044e, \u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 \u0438\u0445 \u0441\u0440\u0435\u0434\u0430\u0445.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u043f\u0440\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a \u0438\u043c\u0435\u043d\u0438 \u0443\u0437\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445, \u0430 \u0438\u0437 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e CTE \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0437\u043b\u0430 \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438:<\/p>\n<pre><code class=\"sql\">with recursive  Mapping as ( select  id as node_id,  parent_id as parent_node_id, concat(name, ' (', bytes, ')')as node_name from ZipArchive ),  ...  select fine_tree, node_id, node_level from FineTree ;<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0438\u0436\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430), \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0443\u043c\u043c\u0443 \u0434\u043b\u0438\u043d \u043f\u043e\u043b\u044f <code>full_path<\/code> \u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432, \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"sql\">... select sum(length(full_path)), max(length(full_path)) from FineTree ;<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>\u0421\u043a\u0440\u0438\u043f\u0442<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>MySQL 8.2<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>SQLite 3<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>PostgreSQL 15.6<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>jdk-master.sql<\/code> (\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b &#8212; \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430)<\/p>\n<\/td>\n<td>\n<p align=\"left\">1800 ms<\/p>\n<\/td>\n<td>\n<p align=\"left\">200 ms<\/p>\n<\/td>\n<td>\n<p align=\"left\">500 ms<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 s<\/p>\n<\/td>\n<td>\n<p align=\"left\">1 s<\/p>\n<\/td>\n<td>\n<p align=\"left\">3 s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438<\/p>\n<p align=\"left\">sum(length(full_path))<\/p>\n<p align=\"left\">max(length(full_path))<\/p>\n<\/td>\n<td>\n<p align=\"left\">2 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">1 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">3 s<\/p>\n<p align=\"left\"><code>10 825 567<\/code><\/p>\n<p align=\"left\"><code>265<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u0443\u044e \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/p>\n<figure class=\"float\"><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f SQLite<\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 &#8212; 16<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0421\u0423\u0411\u0414 &#8212; \u0434\u043b\u044f SQLite \u043e\u043d \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439, \u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 MySQL \u0438 PostgreSQL \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>PostgreSQL<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>MySQL<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u044d\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0421\u0423\u0411\u0414 \u0432\u044b\u0432\u043e\u0434 \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 \u0421\u0423\u0411\u0414 \u0441\u043e\u0432\u043f\u0430\u043b\u0438, \u0434\u0430\u0436\u0435 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL \u0438 PostgreSQL. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u043e\u043b\u044f <code>full_path<\/code> \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 255, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e &#171;\u0441\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u043d\u0438\u044f&#187; \u0441 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f PostgreSQL \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>varchar<\/code> \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b, <\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-375132","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375132","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=375132"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/375132\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}