AGGREGATOR SYNC AUTO_INCREMENT

Sets the auto-increment counter on the aggregators (master or child).

Syntax

AGGREGATOR SYNC AUTO_INCREMENT [ON <database>[.<table>]] [ALL]

Remarks

  • This command is used to fix one or more auto_increment counters that are lower than the currently inserted values in a table. Run this command on the aggregator that has a broken counter.

  • It updates the auto_increment counter by querying the leaves for the next appropriate value. This value is used if it does not decrease the counter.

  • Specifying ALL will run the sync on all aggregators, instead of just the current aggregator.

  • This command causes implicit commits. Refer to COMMIT for more information.

  • Refer to the Permission Matrix for the required permission.

Example AGGREGATOR SYNC AUTO_INCREMENT Scenario

When a new table is created with an auto_increment using existing data (that already has auto_increment values assigned), the new table must generate a new auto_increment counter that does not collide with the existing data. But on sharded tables, the auto_increment counter completely ignores the inserts and does not update the counter.

In order to get the auto_increment values to start from the existing data, run AGGREGATOR SYNC AUTO_INCREMENT on each aggregator after loading the data.

Examples

Create a table and insert an explicit value in the field with AUTO_INCREMENT enabled, to simulate previously generated data.

CREATE TABLE roll (id BIGINT PRIMARY KEY AUTO_INCREMENT);
INSERT INTO roll VALUES (5);
SELECT * FROM roll;
+----+
| id |
+----+
|  5 |
+----+

Now add a new row to the table, without adding values to the field with AUTO_INCREMENT enabled.

INSERT INTO roll VALUES(null);
SELECT * FROM roll;
+----+
| id |
+----+
|  1 |
|  5 |
+----+

The value generated by the AUTO_INCREMENT counter for the new row is 1, because in sharded tables, explicitly inserted values do not affect the automatically generated values.

Now, run the following command independently on each aggregator.

AGGREGATOR SYNC AUTO_INCREMENT;
INSERT INTO roll VALUES (null);
SELECT * FROM roll;
+----+
| id |
+----+
|  5 |
|  1 |
|  6 |
+----+

The new row has a value of 6.

You can also make the counter (new automatically generated values) for inserts on the master aggregator start from a higher value. The following example starts the counter from 100.

INSERT INTO roll VALUES (99);
AGGREGATOR SYNC AUTO_INCREMENT;
DELETE FROM roll WHERE id = 99;
INSERT INTO roll VALUES (null);
SELECT * FROM roll;
+-----+
| id  |
+-----+
|   1 |
|   6 |
|   5 |
| 100 |
+-----+

This approach will only increase the counter if there is data higher than the current counter value; it will not decrease the counter.

Last modified: January 9, 2023

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK