Skip to content

Prototype Postgres extension to prevent sequential scans

Notifications You must be signed in to change notification settings

brendar/seq_ban

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is just an experiment to see what it would look like to build a postgres extension to prevent sequential scans.

Building

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-postgres

Connect to the container

PGPASSWORD=asdf psql -h localhost -p 5432 -U postgres

Setup

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)

About

Prototype Postgres extension to prevent sequential scans

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published