How to Determine which fields on a table are indexed


When evaluating fetch() performance, I am looking to determine all of the fields on a Type that are indexed.

Question 1: Is there an API that I can use to find all the indexed fields without navigating back through the inheritance hierarchy?

Question 2: Which (if any) fields does the platform index by default?

I can find which fields are indexed on a given type that I defined by c3ShowType(MyType) and showing the Type Declaration at the top of the screen to check out a list of the fields that have been indexed on the table (see examples screenshot below --> @db(index=...) ), and if my type inherits another type from a c3 base repository package, I can navigate to c3ShowType(C3BaseType) and do the same thing.


I got an answer to question #1: You can execute a query directly against the database if you have DB-level admin access

Question #2 is still open.


You generally cannot assume you have DbAdmin access.

A better way to determine what fields on a table are indexed etc. is to use the schema() function.
(remember that each type can be spread across many tables)

For example, ServiceAgreement.schema().tables() gives you a list of tables and their properties like indexes and primary keys. If you are only interested in indexes, you could use the code snippet:
ServiceAgreement.schema().tables().flatMap(function(t) {return t.indexes})