Question: **Goal:**

Add a database index to a 'created' field.

**Given:**

There is a custom entity with a base field `created`.
The field is stored the entity table. 
Field source code of the `created` field:

```
$fields['created'] = BaseFieldDefinition::create('created')
  ->setLabel(t('Created'))
  ->setDescription(t('The time that the entity was created.'))
  ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'timestamp',
    'weight' => 3,
    'settings' => [
      'date_format' => 'medium',
      'custom_date_format' => '',
      'timezone' => '',
    ],
  ])
  ->setDisplayConfigurable('view', TRUE);

```

**What I researched:**

I have not found a way to add index using the `\Drupal\Core\Field\BaseFieldDefinition()`.

As I understand indexes are defined in a `@FieldType` plugin. The `created` field is implemented via the `\Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem()` plugin and obviously does not have have indexes there.

P.S. I know, that I can write an updatescript to add an index to the table manually.

Answer: 
Besides the options berdir posted, configurable fields can have manually added indexes via \Drupal\field\Entity\FieldStorageConfig::$indexes

For example, in `field.storage.media.field_media_video_embed_field.yml` file you'd have:

```
indexes:
  field_media_video_embed_field__value:
    - value

```

to add an index on the `value` property. Note the second line in this example is just the index name and has no special meaning and could be anything else, it's just a naming convention. But the third line here needs to be the property name and *not* the SQL database column name (which would be `field_media_video_embed_field__value`).
While the above API approaches are recommended, here's one more raw approach that can be useful for some cases. 

In this case, it adds an SQL index to a base field for the MySQL/MariaDB database engine:

```
/**
 * Add SQL index on published_date base field
 */
function MY_MODULE_update_8010(&$sandbox) {
  // Add index
  // ALTER TABLE $table ADD INDEX $name ($column1, $column2..)
  db_query("ALTER TABLE node_field_data ADD INDEX node_field__published_date (published_date)");
}

```