Skip to content

Add a sorting index to the name column on the Personal Access Tokens Table

Related to #524159 (closed)

What?

Find the best path to add a character limit constraint to the PAT name column without breaking any existing PAT related integrations (internal & external)

Why?

  • Makes the name sort order on the credentials inventory more efficient (>90%)
  • Makes sure external customers aren't affected

Things That Can Go Wrong?

The strategy used to limit the name needs to account for a few of the following:

  • Breaking CI/CD Pipelines
  • Automation scripts that rely on those PAT names
  • Audit logs

Possible Solution

  • The limit should be for new PATs so it doesn't break any token update validations
validates :name, length: { maximum: 255 }, on: :create

The following discussion from !193375 (merged) should be addressed:

  • @ghavenga started a discussion: (+6 comments)

    Problem:

    ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded: ERROR:  index row requires 12248 bytes, maximum size is 8191

    Failure is from the database testing pipeline when attempting to apply this to the sec and ci databases. Not seen this one before.

    It would appear Postgres isn't a fan of indexing large string fields. It would appear that doing so is usually not expected to provide significant performance benefit anyways.

    One thing I do note is your Postgres.ai link does not seem to be making use of this index at all. Given this, perhaps it's not worth bothering to figure out how to make it applyable and just drop it?

Edited by Hakeem Abdul-Razak