Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better: single global sequence vs. sequence per table?

In a JPA/Hibernate application using native Oracle sequences, is it better to use a single global sequence like hibernate_sequence, or to define a separate sequence per table?

It seems like a single sequence is easier to maintain, but could make troubleshooting or ad hoc queries harder by making longer ID's.

like image 298
wrschneider Avatar asked Oct 14 '11 23:10

wrschneider


People also ask

Can we use same sequence for multiple tables?

Show activity on this post. I found the answer: "Sequence numbers are generated independently of tables, so the same sequence can be used for one or for multiple tables."

What is Nocycle sequence?

NOCYCLE. Specify NOCYCLE to indicate that the sequence cannot generate more values after reaching its maximum or minimum value. This is the default. CACHE. Specify how many values of the sequence the database preallocates and keeps in memory for faster access.

What are the keywords that can be used when creating a sequence?

Common sequence words are first, next, second, meanwhile, suddenly, and finally. 'First' signals the first thing someone did in a story or the first step in a procedure. 'Next' signals the next event in a story or the next step in a procedure.

What is the difference between sequence and auto increment in SQL?

The difference between auto-increment columns in SQL Server and sequences in Oracle is that: In SQL Server, you mark a column as an auto-increment column and SQL Server automatically generates new values for the column when you insert a new row.


1 Answers

Although cacheing alleviates it, a sequence can cause contention when multiple sessions require nextvals. If you have one sequence serving all tables then all inserts on all tables will contend for the same sequence. If you are after performance, one sequence for each table will give less contention.

like image 74
Morbo Avatar answered Sep 28 '22 09:09

Morbo