我在 PosgreSQL 中的递归查询性能很差。
psql --version
psql (PostgreSQL) 10.7 (Ubuntu 10.7-1.pgdg16.04+1)
Run Code Online (Sandbox Code Playgroud)
这个想法是拥有树状的评论结构。所以什么时候parent_id
是NULL
父评论,什么时候是整数,什么时候是回复。
我的评论表()的表结构如下\d+ comment
:
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
-----------------+--------------------------+-----------+----------+-------------------------------------+----------+--------------+-------------
id | bigint | | not null | nextval('comment_id_seq'::regclass) | plain | |
website_page_id | bigint | | not null | | plain | |
author_id | bigint | | not null | | plain | |
parent_id | bigint | | | | …
Run Code Online (Sandbox Code Playgroud)