Background
I have many different “things” (item / item / domain item) that are visible to the owners of the “thing” (people). Owners are going to identify their “things” with a number. Instead of showing a large "random" number, I want to show them a small number (preferably a sequence starting with 1), which is easier for people. Owners are very comfortable talking about "my foo 37" and "her bar 128". There the "sequence" may have spaces, but the attached number should remain unchanged during the life of the "thing". So I need a way to generate the “thing” + the owner’s own identifier (currently called the “visible identifier”).
The number of combinations "thing" + owner in a scale of 10k +. Currently, new “things” cannot be dynamically generated, but owners can be.
The number of copies of “pieces” per owner is relatively small, about a dozen per owner, but there is no hard cover that can be obtained from business rules. New instances of "things" are created and deleted frequently.
Considered Parameters
I found a good discussion on the SO Oracle Partitioned Sequence question, which addresses almost the same issue as mine.
So far I have considered the following options:
- I think the standard database sequence will be perfectly fine, but it will require me to dynamically create a large number of “real” + user-specific sequences, as well as resolve the sequence name during insertion. (And discard the sequences when the owner has left.) I'm not sure that creating a huge number of sequences is good practice (I have 10,000 + database objects - a huge amount).
- I also considered the notorious
max(visible_id) + 1 , but we will run into the usual concurrency problems with this, so this is not-go. - Do not save a separate owner identifier in the database, but instead generate it in the Adam Mush selection. This is a great idea, but unfortunately the identifier must be the same during the lifetime of the "thing" instance.
- Avoid the whole problem by letting owners call a “thing.” But they didn't like the idea at all: "Why should I worry, it's so easy to say foo 16."!
Question
Is there any other way to solve this problem or should I start creating sequences dynamically? If the sequences are the answer, please specify what pitfalls may be (for example, implicit commits in DDL).
I'm interested in both Oracle 11gR2 and 12c solutions (if they are different).
Pseudocode to illustrate the question
create table foo ( id number primary key -- the key for computers ,owner_id number ,visible_id number -- the key for humans ,data_ varchar2(20) ); create constraint foo_u1 unique foo(owner_id, visible_id); -- primary key sequence create sequence foo_id_seq; insert into foo values( foo_id_seq.nextval ,1 ,1 -- what to put here ? ,'lorem ipsum' ); insert into foo values( foo_id_seq.nextval ,2 ,1 -- what to put here ? ,'dolor sit amet' ); select visible_id, data_ from foo where owner = 2 order by visible_id;
sql oracle
user272735
source share