nolly: (fluffy dragon)
[personal profile] nolly
I would like to give a serious clue-by-four beating to whoever thought it was a good idea to implement last_insert_id() many versions before adding transactions to MySQL. In a transactional context, it's a possibly useful function, though I prefer specifying what I want the last ID from, a la PG's currval. Outside of one? Dangerously unreliable, a concept one or more of my predecessors completely failed to grasp.

[end rant]

Date: 2008-09-03 04:59 pm (UTC)
From: [identity profile] allaboutm-e.livejournal.com
I'd send sympathy and understanding, but I don't actually understand the rant -- too high tech for moi... so sympathy only, it is

Date: 2008-09-03 05:04 pm (UTC)
From: [identity profile] nolly.livejournal.com
I cou8ld probably exoplain it in person, with hand-waving, but yeah, I didn't expect anyone who wasn't already familiar with the topic to follow in detail.

Date: 2008-09-03 06:30 pm (UTC)
From: [identity profile] gunslnger.livejournal.com
MySQL isn't transactional? That's sucky.

Date: 2008-09-03 06:32 pm (UTC)
From: [identity profile] nolly.livejournal.com
I believe current releases are, but not the older version I'm currently working with, which does have last_insert_id().

Date: 2008-09-04 08:18 am (UTC)
From: [identity profile] dancingguy.livejournal.com
MyISAM isn't transactional, INODB is.

How are you getting burned by last_insert_id ()? I'm using it in my code, and to the best of my knowledge I'm not getting burned by it.

Date: 2008-09-04 02:55 pm (UTC)
From: [identity profile] nolly.livejournal.com
Presumably, you're also using a version more recent than 3.23 -- and yes, we're in the process of migrating away from that (migrating to PostgreSQL 8.3), which is why I'm digging through all the crusty old code.

Due to the non-transactional nature of the interactions in the current system, occasionally another insert happens between the insert and the last_insert_id call, and last_insert_id will return an id from another table altogether.

It's not common, but it is possible.

Also, certain people in the past of this codebase wrote overly clever functions which have been annoying to convert to Postgres.

Date: 2008-09-04 11:02 pm (UTC)
From: [identity profile] dancingguy.livejournal.com
Ah. Yes, that bite you in the ass in certain situations. :-(

Happily, I took a look at my code, and it turns out I'm not using that call after all. :-)

Profile

nolly: (Default)
nolly

December 2011

S M T W T F S
     123
45678910
11121314 151617
18192021 222324
25262728293031

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 26th, 2026 09:10 am
Powered by Dreamwidth Studios