Problem/Motivation

The 'DBTNG' introduced in 7.x was incomplete with regards to temporary table creation.

Proposed resolution

Allow temporary tables to be created through db_select().

Remaining tasks

User interface changes

None.

API changes

Marks db_query_temporary() as deprecated for 8.1.

Original report by @hswong3i

Beside using db_query_range() directly, we can also use db_select()->range(); BTW, now we are missing db_select()->temporary() as it is not yet implemented, so db_query_temporary() is our only choice.

This patch add the new method db_select()->temporary(), which also coming with additional simpletest test case. Tested with MySQL + simpletest and pass.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Unfrozen changes Unfrozen because it only improves the database API, and deprecates an old function for 8.1
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hswong3i’s picture

According chx's suggestion from #drupal, simplify the function temporary($tablename = NULL) as below:

  public function temporary($tablename = NULL) {
    $this->temporary = $tablename;
    return $this;
  }
Dries’s picture

It is not clear why you create the temporary table in a separate request. The phpdoc does not explain the 'why'.

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

Crell’s picture

Apropos of the discussion over in #349500: db_query_temporary() should generate a table name, we shouldn't allow callers to specify their own table name. I'm actually thinking it would be better here to have an alternate execute method, executeTemporary() or some such, that takes the built query and makes a temp table out of it and returns the table name it generated, just like db_query_temporary() will after that patch lands. That means this patch is blocked on that one. hswong, can you reroll with that approach as soon as the other patch goes in? Thanks.

Crell’s picture

Version: 7.x-dev » 8.x-dev
Assigned: hswong3i » Unassigned

Sigh. I guess this didn't happen. Sadness.

catch’s picture

Priority: Critical » Major

Downgrading all D8 criticals to major per http://drupal.org/node/45111

drunken monkey’s picture

Subscribing.
While probably not used very often, this is one of the (few) holes in the API.

jhedstrom’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.51 KB

Picking this up 4 years later...

Status: Needs review » Needs work

The last submitted patch, 10: db-select-temporary-332353-10.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
4.12 KB
6.64 KB

Since this involves a change to an interface, I'm guessing it might be too late for 8.0?

Status: Needs review » Needs work

The last submitted patch, 12: db-select-temporary-332353-12.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
1.57 KB
6.67 KB
jhedstrom’s picture

Issue summary: View changes
drunken monkey’s picture

FileSize
6.16 KB
  1. +++ b/core/includes/database.inc
    @@ -321,6 +321,8 @@ function db_query_range($query, $from, $count, array $args = array(), array $opt
    + * @deprecated in Drupal 8.0.x, will be removed before 8.1.0.
    

    Why did you add this? Seems no other database function is deprecated, why should this be? (Or, in any case, that's a different issue.)

  2. +++ b/core/lib/Drupal/Core/Database/Query/Select.php
    @@ -572,6 +572,20 @@ public function execute() {
    +    // Note that validation routines in preExecute() may throw exceptions instead.
    
    +++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
    @@ -489,6 +489,14 @@ public function preExecute(SelectInterface $query = NULL);
    +   * Executes a SELECT query string and saves the result set to a temporary table.
    

    Overlong comment lines.

  3. +++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php
    @@ -489,6 +489,14 @@ public function preExecute(SelectInterface $query = NULL);
    +   * @return string
    +   *   The name of the temporary table.
    

    Should also list NULL for the error case. Should also list the exception that could be thrown, but it seems that isn't the case anywhere else in this interface either, anyways.

Amended patch attached. Otherwise, this looks great, thanks a lot for posting!
I do hope we can still get this in, it seems innocent enough and has been broken for two major versions now. But of course, that's not any argument here …

jhedstrom’s picture

The db_query_temporary() function isn't used at all by core, and because it isn't just a wrapper for this new method, then two different code paths need to be maintained. Seemed reasonable to deprecate and eventually remove.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

monkey: Please include an interdiff, especially when fixing your own review.

I'm fine with this, including in 8.0. Up to catch if it gets bumped to 8.1.

(I would like to mark all of the db_*() functions deprecated but we can't remove them in 8.x now, sadly.)

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Postponed

We can deprecate stuff for 9.x - this issue should deprecate db_query_temporary().

This issue does not fall into the list of unfrozen changes in https://www.drupal.org/core/beta-changes. This issue looks like a good candidate for 8.1

drunken monkey’s picture

monkey: Please include an interdiff, especially when fixing your own review.

OK, sorry. Here is an interdiff for my previous patch, and a new patch with the @deprecated added again, along with an interdiff.
However, in my opinion, we should mark either all or none of these as deprecated, and in a separate issue. This has little to do with the issue at hand.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drunken monkey’s picture

Status: Postponed » Needs review

Active again, I guess?

The last submitted patch, 20: 332353-20--executeTemporary_for_select_class.patch, failed testing.

drunken monkey’s picture

drunken monkey’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

Tagging for IS update as after so many years I know things are different for D10 and imagine the fix (if any) will be different.

Moving to PNMI if someone could answer if this is still an issue for 10.1 (apologies for not knowing myself just trying to help with the queue)

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

If still a valid feature request please reopen updating issue summary per #39

Thanks!