I’m working on an application with a PostgreSQL back end. There is a many-to-many relationship between items
in one table and tags
in another table. The specs require that the application be able to respond to frequent queries that provide a list of tags
as parameters and expect in response a list of all items
which contain only those tags
but not necessarily all of those tags.
Is there an efficient (non-exponential complexity) way to structure my database (or application) to suit this task? At launch, I shall have on the order of 12K items
and 1K tags
.
E.g.
A user requests a list of all items
for tags a
, b
, and c
.
The response contains items with the following tag sets:
{}
{a}
{a,b,c}
The response must not contain items with the following tag sets:
{d}
{a,b,c,d}
The structure of tags
table is as follows:
CREATE TABLE tags (
id integer NOT NULL,
name text NOT NULL,
description text,
revision_id integer
);