Hierarchical tagging in SQL

后端 未结 5 1921
天涯浪人
天涯浪人 2020-12-25 08:59

I have a PHP web application which uses a MySQL database for object tagging, in which I\'ve used the tag structure accepted as the answer to this SO question.

I\'d l

5条回答
  •  长情又很酷
    2020-12-25 09:17

    I would use some kind of array to store the children tags, this should be a lot faster than joining a table on itself (especially if you have a large number of tags). I had a look, and I can't tell if mysql has a native array data type, but you can emulate this by using a text column and storing a serialized array in it. If you want to speed things up further, you should be able to put a text search index on that column to find out which tags are related.

    [Edit] After reading Ali's article, I did some more hunting and found this presentation on a bunch of approaches for implementing hierarchies in postgres. Might still be helpful for explanatory purposes.

提交回复
热议问题