Moving from TPS to PostgreSQL: do my dictionary KEYs need matching indexes on the server?

Applies to: every Clarion version with a SQL driver; asked for PostgreSQL in 2017, the answers name MSSQL too.

Problem

A shop converting TPS files to PostgreSQL recreated every TPS key as a PostgreSQL index because they believed the compiled SET/NEXT code needed them, and asked whether going all-PROP:SQL would remove that need.

Solution

  1. A KEY in the dictionary of a SQL table is used by the driver only to build the ORDER BY clause of the SELECT it generates (ascending/descending per component). It does not have to exist on the server. Twenty keys in the FILE and none in PostgreSQL is fine; the poster's earlier errors were his own mistake.
  2. Which server index gets used is the server's decision, based on row counts and distribution; a query that returns a large share of the table is often a full scan on purpose. Create server indexes for the sorts and filters you actually run, not one per Clarion key.
  3. Do not rely on SET(Key,Key) to limit rows on SQL: the result set is undefined and can be the whole table. The browse template does the same. Filter first: MyFile{PROP:WHERE} = '<your SQL WHERE text>' then SET(MyF:SomeKey) and the LOOP.
  4. A case-insensitive key in Clarion becomes ORDER BY UPPER(column); an index on the plain column cannot serve it. The poster used the citext type for those columns and reported it working.
  5. With PROP:SQL or PROP:SQLRowSet the statement is entirely yours; Clarion keys play no part, and you add the ORDER BY yourself over any columns. Going all-PROP:SQL is not necessary; the driver's generated SQL is good, and hand-built WHERE strings get messy.
  6. Look at BUFFER to fetch several rows per round trip; the template does not do that by default.

Caveats

  • Optimizer hints exist on Oracle, not on PostgreSQL; the thread's view was that the server knows best.
  • The shop in question used no templates; the SET(Key,Key) warning applies to template browses as well.

Today (2026)

Unchanged: dictionary keys still drive ORDER BY only, server indexes are a server-side design, and PROP:WHERE before SET remains the way to bound a loop. Not re-tested for this entry.

Sources: Jim W. (Apr 2017, the question), Sean H., Arnor B., Jon W. (Apr 2017) in softvelocity.clarion.databasedrivers.