pgexperts / pgx_scripts

A collection of useful little scripts for database analysis and administration, created by our team at PostgreSQL Experts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fk_no_index.sql returns zero rows

peterhanneman opened this issue · comments

Using Postgres 9.5.3 this query returns zero rows when I know that I have missing referencing indexes.

Me too.
Using Postgres 9.6.6, and get same result (zero result rows).

Environment

user=# select version();
                                         version                                          
------------------------------------------------------------------------------------------
 PostgreSQL 9.6.6 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
(1 row)

Test

CREATE TABLE PERSONS (
  id BIGSERIAL PRIMARY KEY,
  name VARCHAR(50) NOT NULL DEFAULT ''
);

CREATE TABLE PERSON_JOBS (
  id BIGSERIAL PRIMARY KEY,
  person_id BIGSERIAL REFERENCES PERSONS(id) NOT NULL,
  name VARCHAR(50) NOT NULL DEFAULT ''
);
-- Miss to create index on foreign key!!
-- CREATE INDEX person_jobs_person_id ON PERSON_JOBS(person_id);

-- But cannot receive result rows.

@peterhanneman @doyaaaaaken the WHERE clause

WHERE table_mb > 9
    AND ( writes > 1000
        OR parent_writes > 1000
        OR parent_mb > 10 )

filters only tables that have size more than 9GB, try to remove WHERE clause