by dahdum · 4y ago · 0 comments
Nowadays I nearly always store the assigned tags as an integer array column in Postgres, then use the intarray extension to handle the arbitrary boolean expression searches like “((1|2)&(3)&(!5))”. I still have a tags table that stores all the metadata / hierarchy / rules, but for performance I don’t use a join table. This has solved most of my problems. Supertags just expand to OR statements when I generate the expression. Performance has been excellent even with large tables thanks to pg indexing.
I’ve used array column in PG before, haven’t indexed arrays though.
People usually go with GIN indexes, that can be used on the contains, overlaps or equals comparisons.
I think the relation was that each user could have mutlitple posts that each contain multiple tags.
Where each tag is global with an user ids stored with the user Id as the key. Or something approximatating that.
Mainly to not need insane queries for many to many relationships. O(1) baby.
I'm not sure about implementation/support in Postgres specifically, but in the general case of a column of tag bitfields, the database could easily maintain a global popcount (ie, "number of rows with this tag") and soft-delete flag for each tag, and clear any soft-deleted tags on (possibly-only-write-)access. When a soft-deleted tag reaches popcount == zero, it counts as garbage collected and can be reused for a new tag.
Nowadays you can just use a tagging component with integrated search for the UI.
How high is the business risk if you have a random tag with no name? Skip it’s display jn the UI