473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Transactions and insertion ordering

Hi,

I'm trying to work out how to make sure things are read from a table in
a consistent order. The table represents a queue of items and also the
history of those items.

Even with "serializable" transaction isolation I can begin two
transactions, insert a record in each, commit the second transaction
first. This second record is now visible and can be read from the queue.
But when I commit the first this one appears before the second one. This
could then be read from the queue second but when I rescan the table to
view history it looks like it was read first.

Are there any ways to make this work a little more intuitively?
Basically I guess I want to be able to model a queue effectively.

James
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
6 1543
nextval() should return value in the order they were called, rather
than commit time. I hope you're not relying on the unordered results of
a table scan remaining stable. Tables have no intrinsic "order", only
one inposed by an external sequence.

Hope this helps,

On Thu, Jun 10, 2004 at 09:28:50AM +0100, James Pharaoh wrote:
Hi,

I'm trying to work out how to make sure things are read from a table in
a consistent order. The table represents a queue of items and also the
history of those items.

Even with "serializable" transaction isolation I can begin two
transactions, insert a record in each, commit the second transaction
first. This second record is now visible and can be read from the queue.
But when I commit the first this one appears before the second one. This
could then be read from the queue second but when I rescan the table to
view history it looks like it was read first.

Are there any ways to make this work a little more intuitively?
Basically I guess I want to be able to model a queue effectively.

James


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAyDTVY5Twig3Ge+YRAjwZAJ0RhFkKEDuooL0p1Qt26W x24/5wDQCcDEwj
BEY7PEFrpP7qlBtCRzhsf2U=
=/RJx
-----END PGP SIGNATURE-----

Nov 23 '05 #2
nextval() should return value in the order they were called, rather
than commit time. I hope you're not relying on the unordered results of
a table scan remaining stable. Tables have no intrinsic "order", only
one inposed by an external sequence.

Hope this helps,

On Thu, Jun 10, 2004 at 09:28:50AM +0100, James Pharaoh wrote:
Hi,

I'm trying to work out how to make sure things are read from a table in
a consistent order. The table represents a queue of items and also the
history of those items.

Even with "serializable" transaction isolation I can begin two
transactions, insert a record in each, commit the second transaction
first. This second record is now visible and can be read from the queue.
But when I commit the first this one appears before the second one. This
could then be read from the queue second but when I rescan the table to
view history it looks like it was read first.

Are there any ways to make this work a little more intuitively?
Basically I guess I want to be able to model a queue effectively.

James


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAyDTVY5Twig3Ge+YRAjwZAJ0RhFkKEDuooL0p1Qt26W x24/5wDQCcDEwj
BEY7PEFrpP7qlBtCRzhsf2U=
=/RJx
-----END PGP SIGNATURE-----

Nov 23 '05 #3
On Thu, Jun 10, 2004 at 20:15:53 +1000,
Martijn van Oosterhout <kl*****@svana.org> wrote:
nextval() should return value in the order they were called, rather
than commit time. I hope you're not relying on the unordered results of
a table scan remaining stable. Tables have no intrinsic "order", only
one inposed by an external sequence.


This isn't really guarenteed with nextval. I think it will work if you
are just reserving one value at a time (which is the default).

I think the real problem is that the original poster needs to precisely
define what determines order. If the precise definition is transaction
commit order, I think that is going to be hard to do exactly right.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #4
On Thu, Jun 10, 2004 at 20:15:53 +1000,
Martijn van Oosterhout <kl*****@svana.org> wrote:
nextval() should return value in the order they were called, rather
than commit time. I hope you're not relying on the unordered results of
a table scan remaining stable. Tables have no intrinsic "order", only
one inposed by an external sequence.


This isn't really guarenteed with nextval. I think it will work if you
are just reserving one value at a time (which is the default).

I think the real problem is that the original poster needs to precisely
define what determines order. If the precise definition is transaction
commit order, I think that is going to be hard to do exactly right.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5
On Thu, 2004-06-10 at 14:47, Bruno Wolff III wrote:
I think the real problem is that the original poster needs to precisely
define what determines order. If the precise definition is transaction
commit order, I think that is going to be hard to do exactly right.


Yes, that is what I want. So I can guarantee that the order of the IDs
in the database will be the same as the order in which they are taken
out of the queue.

I think I've come up with a reasonable solution now though. I can lock
the record representing the queue in another table FOR UPDATE and then
do the insert, then no other process will be able to gain that lock
until I complete. Best bit is other items can still insert concurrently,
but only one per queue, which is exactly what I was after.

Thanks for the help anyway ;-)

James
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #6
On Thu, 2004-06-10 at 14:47, Bruno Wolff III wrote:
I think the real problem is that the original poster needs to precisely
define what determines order. If the precise definition is transaction
commit order, I think that is going to be hard to do exactly right.


Yes, that is what I want. So I can guarantee that the order of the IDs
in the database will be the same as the order in which they are taken
out of the queue.

I think I've come up with a reasonable solution now though. I can lock
the record representing the queue in another table FOR UPDATE and then
do the insert, then no other process will be able to gain that lock
until I complete. Best bit is other items can still insert concurrently,
but only one per queue, which is exactly what I was after.

Thanks for the help anyway ;-)

James
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Murad Nayal | last post by:
Hello, I vaguely remember reading in the manual that the order of the retrieved rows in a response to a select statement is unpredictable (unless you use an order by clause). this possibly...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
10
by: Tom | last post by:
Hi I am looking for an optimal data-structure in order to replace a map<int,float>. I use it as some kind of sparse array representation. The facts: - the population in the data-structures...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
0
by: James Pharaoh | last post by:
Hi, I'm trying to work out how to make sure things are read from a table in a consistent order. The table represents a queue of items and also the history of those items. Even with...
10
by: BLUE | last post by:
Is there any way to use transactions if I use DbProviderFactory class to abstract from the provider? If not, is there any way to manage concurrency in a "universal"/provider indipendent mode? ...
3
by: BLUE | last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL? Thanks, Luigi.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.