This is just an experiment to see what it would look like to build a postgres extension to prevent sequential scans.
Build the image:
docker build -t seq-ban-postgres .Run the container:
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=asdf --name seq-ban-dev seq-ban-postgresConnect to the container
PGPASSWORD=asdf psql -h localhost -p 5432 -U postgresSetup
CREATE TABLE foos (id BIGINT PRIMARY KEY);
INSERT INTO foos (id) VALUES (1),(2),(3);Testing
postgres=# SELECT COUNT(*) FROM foos;
count
-------
3
(1 row)
postgres=# SET seq_ban.enabled = true;
SET
postgres=# SELECT COUNT(*) FROM foos;
ERROR: sequential scan detected in query plan
HINT: Add an appropriate index or rewrite the query to avoid sequential scans.
postgres=# SET seq_ban.mode = 'warning';
SET
postgres=# SELECT COUNT(*) FROM foos;
WARNING: sequential scan detected in query plan
HINT: Add an appropriate index or rewrite the query to avoid sequential scans.
count
-------
3
(1 row)
postgres=# SET seq_ban.allow_next = true;
SET
postgres=# SELECT COUNT(*) FROM foos;
count
-------
3
(1 row)
postgres=# SELECT COUNT(*) FROM foos;
WARNING: sequential scan detected in query plan
HINT: Add an appropriate index or rewrite the query to avoid sequential scans.
count
-------
3
(1 row)