I have a log table that is inherited by several tables:
CREATE TABLE log (
IdGlobal uuid NOT NULL DEFAULT uuid_generate_v1(),
Version integer NOT NULL DEFAULT 0,
ChangeDate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
IsDeleted bool DEFAULT false
);
CREATE TABLE Customer (
Id SERIAL PRIMARY KEY,
Code text NOT NULL UNIQUE,
Name text NOT NULL,
) INHERITS (log);
However, I wonder if have it will make a impact for performance. The DB is for a SASS app in development (early stage) and will have 1 schema=1 company.
I understand that the main advantage in postgres is about partitioning, but my use case is more related to typical OOP.
The log table increase size will hurt me in the long run? Where I put the indexes? In the parent or in the child’s? (I will make searches by IdGlobal & version)
The log table size won’t affect the queries against Customer table, it’s actually the other way: by default SELECTs, UPDATEs and DELETEs from the log table will run against the Customer table as well, unless you specify the ONLY clause, i.e.
SELECT * FROM ONLY log;
Indexes and constraints (unique, primary and foreign key) apply to a single table only, not to the whole inheritance hierarchy, so, unfortunately, you need to create them separately for the parent and for the child tables. This also means that you can’t have a unique index that covers all the tables in the hierarchy.