# Row-based Replication With No Primary Key

{% hint style="info" %}
The terms *master* and *slave* have historically been used in replication, and MariaDB has begun the process of adding *primary* and *replica* synonyms. The old terms will continue to be used to maintain backward compatibility - see [MDEV-18777](https://jira.mariadb.org/browse/MDEV-18777) to follow progress on this effort.
{% endhint %}

MariaDB improves on row-based [replication](https://mariadb.com/docs/server/ha-and-performance/standard-replication) (see [binary log formats](https://mariadb.com/docs/server/server-management/server-monitoring-logs/binary-log/binary-log-formats)) of tables which have no primary key but do have some other index. This is based in part on the original Percona patch `row_based_replication_without_primary_key.patch`, with some additional\
fixes and enhancements.

When row-based replication is used with [UPDATE](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/changing-deleting-data/update) or [DELETE](https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/changing-deleting-data/delete), the replica needs to locate each replicated row based on the value in columns. If the table contains at least one index; an index lookup will be used (otherwise a table scan is needed for each row, which is extremely inefficient for all but the smallest table and generally to be avoided).

In MariaDB, the slave will try to choose a good index among any available:

* The primary key is used, if there is one.
* Else, the first unique index without `NULL`-able columns is used, if there is\
  one.
* Else, a choice is made among any normal indexes on the table (e.g. a [FULLTEXT](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/optimization-and-indexes/full-text-indexes) index is not considered).

The choice of which of several non-unique indexes to use is based on the\
cardinality of indexes; the one that is most selective (has the smallest average number of rows per distinct tuple of column values) is preferred. Note that for this choice to be effective, for most storage engines (like MyISAM, InnoDB) it is necessary to make sure [ANALYZE TABLE](https://mariadb.com/docs/server/reference/sql-statements/table-statements/analyze-table) has been run on the slave, otherwise statistics about index cardinality is not available. In the absence of index cardinality, the first unique index is chosen, if any, else the first non-unique index.

## See Also

*

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/ha-and-performance/standard-replication/row-based-replication-with-no-primary-key.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
