Create this schema:
create table t (i int primary key, j int);
create index i on t (j);
Now, when trying to discover the index i from the information_schema, one might think the following query could be useful, yet it does not return any data:
select *
from information_schema.STATISTICS s
where not exists (
select 1
from information_schema.TABLE_CONSTRAINTS c
where s.INDEX_SCHEMA = c.CONSTRAINT_SCHEMA
and s.INDEX_NAME = c.CONSTRAINT_NAME
and s.TABLE_NAME = c.TABLE_NAME
);
Add an additional predicate, and it now returns the index, as expected:
select *
from information_schema.STATISTICS s
where not exists (
select 1
from information_schema.TABLE_CONSTRAINTS c
where s.INDEX_SCHEMA = c.CONSTRAINT_SCHEMA
and s.INDEX_NAME = c.CONSTRAINT_NAME
and s.TABLE_NAME = c.TABLE_NAME
)
and s.index_name = 'i';
select version(); yields 5.5.58. I’m using the latest version from docker: memsql/cluster-in-a-box