PgFirstAid: PostgreSQL function for improving stability and performance
1–10 of 24 posts
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#2Did you consider making this a view instead? Just curious if there is a reason why you couldn't.
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#3Very nice! Did you consider making this a view instead? Just curious if there is a reason why you couldn't.
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#4There are multiple reasons for tables not having primary keys. Log tables are one example.
Excessive sequential scans is also not a problem for small tables.
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#5I'm looking forward to trying this out on my postgres databases.
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#6I would disagree on the fact that a table without a primary key is a critical problem. There are multiple reasons for tables not having primary keys. Log tables are one example. Excessive sequential scans is also not a problem for small tables.
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#7Re: PgFirstAid: PostgreSQL function for improving stability and performance
#8Re: PgFirstAid: PostgreSQL function for improving stability and performance
#9Why are indexes on foreign keys required? If I'm doing a join, it's going to select the primary key of the other table, how will an index on the foreign key help?
Re: PgFirstAid: PostgreSQL function for improving stability and performance
#10I would disagree on the fact that a table without a primary key is a critical problem. There are multiple reasons for tables not having primary keys. Log tables are one example. Excessive sequential scans is also not a problem for small tables.
When I was first learning SQL I was pretty firmly in the "use natural keys" department. And when the natural key was every single column I would go "whats the point?" shrug and have no primary key. Until I started getting duplicated rows
insert into customer_email (name, address) values ('bob', 'bob@bobco.com');
insert into customer_email (name, address) values ('bob', 'bob@bobco.com');
Duplicate rows a. tend to mess up your query results and b. are surprisingly difficult to remove. If I remember correctly after spending far too long trying to find a pure sql solution I ended up writing a program that would find the duplicates, delete them(all of them as there is no way to delete all but one) then re insert them. and adding that missing primary key.I still like natural keys more than I probably should. (you still need a key to prevent functional duplicates, even when using a surrogate key, why not cut out the middle man?) But am no longer so militant about it(mainly because it makes having dependent tables a pain)