Dealing with auto-increment ID gaps in OceanBase MySQL mode during mass data insertion

Setup

I’m using OceanBase Community 4.2.1 in MySQL mode. We’re moving our data from MySQL 5.7 to OceanBase and we’ve run into a problem with how auto-increment IDs work when we do big inserts.

The issue

When we insert a lot of rows at once (like 10,000), OceanBase leaves bigger gaps in the auto-increment IDs than MySQL did. This is messing up how our app syncs data.

What we’ve tried

We made a test table with partitions and did a big insert. OceanBase gave us IDs like 1, 2, 3, then jumped to 10001, 10002, and so on. MySQL 5.7 would have just counted up from 1 to 10000 without gaps.

We tried setting auto_increment_increment to 1 but it didn’t help. We also tried smaller batches of 100 rows, which helped a bit but didn’t fix it completely.

What we want to know

Is this how OceanBase is supposed to work in MySQL mode? Are there other ways we can do big inserts without getting these ID gaps? It’s really important for how our system works.

Any ideas would be super helpful!

I’ve encountered similar challenges when working with distributed databases. From what I understand, OceanBase’s behavior is likely designed to optimize performance in a distributed environment.

One potential solution is to implement a custom ID generation strategy. You could create a dedicated service that manages ID allocation, ensuring sequential numbers without gaps. This approach allows for better control and consistency across your system.

Another option worth exploring is the use of globally unique identifiers (GUIDs) instead of sequential IDs. While this requires some refactoring, it can solve synchronization issues and provide better scalability in distributed systems.

Have you considered using OceanBase’s built-in sequence objects? They might offer more predictable behavior for ID generation compared to auto-increment columns.

Ultimately, adapting your application to be less reliant on strictly sequential IDs could provide long-term benefits, especially as you scale your system across distributed environments.

hey there, i’ve run into this too. oceanbase does this to handle lots of inserts at once without slowdowns. have u tried using a sequence instead? it might give u more control over the ids. or maybe look into using uuids if ur app can handle it. good luck!

I’ve dealt with similar issues when migrating from MySQL to other database systems. In my experience, the auto-increment behavior you’re seeing in OceanBase is likely intentional for performance reasons, especially in distributed environments.

One approach that worked for me was to use a separate sequence generator for IDs instead of relying on auto-increment. This gives you more control over ID generation and can help maintain consistency across your application.

Another option to consider is adjusting your application logic to be less dependent on sequential IDs. This might involve using UUIDs or composite keys that include other meaningful data.

If you absolutely need sequential IDs without gaps, you might want to look into using a separate table as an ID generator, where you can implement your own locking mechanism to ensure sequential allocation. This comes with its own performance trade-offs, though.

Have you considered reaching out to OceanBase support? They might have specific recommendations for handling this in their system. In my experience, database vendors often have workarounds or best practices for these kinds of migration challenges.