Posted by chx on June 4, 2007 at 12:52pm
| Project: | Drupal core |
| Version: | 6.x-dev |
| Component: | database system |
| Category: | task |
| Priority: | normal |
| Assigned: | chx |
| Status: | closed (fixed) |
Issue Summary
The old issue had a way too high s/n ratio. However, the patch was tested and since then only node creation has changed and I checked that. So it's ready. Note that currval of pgsql is per connection so that's not a problem.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| db_last_insert_id_12.patch | 26.92 KB | Ignored: Check issue status. | None | None |
Comments
#1
Dries asked to link to the old issue. I am not doing that as it's a waste of time, instead I am listing the raised concerns and the solutions.
#2
The fact that this issue was forked makes me reluctant to commit this patch. I still have to read up on the old issue -- regardless of the summary.
#3
Keeping up with HEAD and Dries asked to remove the already obsolete pconnect comment.
#4
Committed to CVS HEAD. Not sure who to credit -- credit is in the other issue. Thanks all! :)
#5
upgrade docs: db_next_id() is now gone, among other developer-visible changes of this patch.
http://drupal.org/node/114774/edit
#6
Uh. The sequences table is not used only for incrementing database keys. It is also a persistent counter API in Drupal. Now that it's gone, what, people should bloat the variables table with counter variables and implement their own counting?
#7
Having a persistent counter in Drupal is useful. Maybe I want to keep track of the number of times something happens. I can do that by calling db_next_id().
Just because Drupal's emulation of database autoincrementation used db_next_id() does not mean that db_next_id() should be taken out. It simply means that autoincrementation should be done another way.
It's like autoincrementation of database rows is a hamburger. db_next_id() is mustard. So I walk into the cafe and find the mustard gone. When I ask why they no longer have mustard I am told that they are not serving hamburgers anymore. But I was putting mustard on my fries, not on a hamburger.
If db_next_id() is no longer available, and I want to count something and have that count stick, I have the following options. (1) I can do a variable_set(). Great. But now that counter is getting pulled needlessly into memory on every request, even if I only need it sporadically. (2) I can have my own database table. This seems kind of silly. Why reimplement something as simple as a counter table when for years we've already had one in Drupal's core API -- the sequences table.
So what I would like to see is either (a) (preferred) bring back the sequences table and db_next_id(). Just don't use it to emulate autoincrementation of database rows -- use native database autoincrementation for that. (b) get back persistent counter functionality by having variables that are not loaded on every request (145164?) and a drupal_counter($counter_name) function in common.inc.
#8
a) makes sense to me.
even worse than variables being called into memory on every load, a variable_set() is very expensive and can kill you if your burgers are very popular.
#9
#10
So, what do you guys think of this?
#11
Following up on this,
db_next_idwas never a general counter API -- on postgresql where sequences are used, you need to create them either by creating a serial field in a table or explicitly creating the sequence. So, if we want a general counter API, that's totally independent of this issue -- please open another.#12
upgrade docs still need fixing. see #5 above.
#13
document updated: http://drupal.org/node/114774#db_last_insert_id
#14