Problem/Motivation

Looking at PostgreSQL logs, these SELECT ... FROM information_schema.columns ... are consistently slow, e.g. > 5 ms (or 10-20 ms) while almost everything else is < 2 ms on my system. This should be cached someway.

Proposed resolution

Change to querying the pg_attribute and pg_attrdef tables directly for the bytea and sequence data for a table.

Currently this has decreased the testbot run time by 10 minutes, which takes it to around ~51 minutes from 1 hour 2 minutes. This will save on server time. Additional PHP optimizations help reduce the test bot time on PHP 7 to ~38 minutes.

Remaining tasks

  • Do research (bzrudi71) - DONE
  • Write a patch (mradcliffe, alexpott) - DONE
  • Review patch (daffie, bzrudi71) -
  • Performance review - DONE

User interface changes

None

API changes

Table information is gathered in a different way with potentially some differences for PostgreSQL. This does not seem to have any affect on tests.

Data model changes

None.

For the committer

Can bzrudi71 also get commit credits for being the one that came with the solution for the problem.

CommentFileSizeAuthor
#40 1079762-40.patch3.83 KBmradcliffe
#31 1079762-31.patch4.64 KBalexpott
#31 29-31-interdiff.txt5.47 KBalexpott
#29 interdiff-1079762-23-29.txt758 bytesbzrudi71
#29 drupal-1079762-information-schema-29.patch2.07 KBbzrudi71
#23 drupal-1079762-information-schema-23.patch2.11 KBmradcliffe
#23 interdiff-1079762-21-23.txt1.08 KBmradcliffe
#21 drupal-1079762-information-schema-21.patch2.08 KBmradcliffe
#21 interdiff-1079762-19-21.txt1.07 KBmradcliffe
#19 interdiff-1079762-15-19.txt1.41 KBmradcliffe
#19 drupal-1079762-information-schema-19.patch2.08 KBmradcliffe
#15 interdiff-1079762-13-15.txt1.27 KBmradcliffe
#15 drupal-1079762-information-schema-15.patch1.61 KBmradcliffe
#13 drupal-1079762-information-schema-12.patch1.63 KBmradcliffe
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ogi’s picture

Category: feature » bug
Priority: Normal » Major

This is not a feature. It's a bug. It eats a lot of total query time because this query is used often. columns is a view and is intended for admin applications, not for all insert/update queries. The Drupal query should be rewritten so that it's faster. I'm considering this a major performance bug. Here is the definition of this view:

                     View "information_schema.columns"
          Column          |                Type                | Modifiers
--------------------------+------------------------------------+-----------
 table_catalog            | information_schema.sql_identifier  |
 table_schema             | information_schema.sql_identifier  |
 table_name               | information_schema.sql_identifier  |
 column_name              | information_schema.sql_identifier  |
 ordinal_position         | information_schema.cardinal_number |
 column_default           | information_schema.character_data  |
 is_nullable              | information_schema.character_data  |
 data_type                | information_schema.character_data  |
 character_maximum_length | information_schema.cardinal_number |
 character_octet_length   | information_schema.cardinal_number |
 numeric_precision        | information_schema.cardinal_number |
 numeric_precision_radix  | information_schema.cardinal_number |
 numeric_scale            | information_schema.cardinal_number |
 datetime_precision       | information_schema.cardinal_number |
 interval_type            | information_schema.character_data  |
 interval_precision       | information_schema.character_data  |
 character_set_catalog    | information_schema.sql_identifier  |
 character_set_schema     | information_schema.sql_identifier  |
 character_set_name       | information_schema.sql_identifier  |
 collation_catalog        | information_schema.sql_identifier  |
 collation_schema         | information_schema.sql_identifier  |
 collation_name           | information_schema.sql_identifier  |
 domain_catalog           | information_schema.sql_identifier  |
 domain_schema            | information_schema.sql_identifier  |
 domain_name              | information_schema.sql_identifier  |
 udt_catalog              | information_schema.sql_identifier  |
 udt_schema               | information_schema.sql_identifier  |
 udt_name                 | information_schema.sql_identifier  |
 scope_catalog            | information_schema.sql_identifier  |
 scope_schema             | information_schema.sql_identifier  |
 scope_name               | information_schema.sql_identifier  |
 maximum_cardinality      | information_schema.cardinal_number |
 dtd_identifier           | information_schema.sql_identifier  |
 is_self_referencing      | information_schema.character_data  |
 is_identity              | information_schema.character_data  |
 identity_generation      | information_schema.character_data  |
 identity_start           | information_schema.character_data  |
 identity_increment       | information_schema.character_data  |
 identity_maximum         | information_schema.character_data  |
 identity_minimum         | information_schema.character_data  |
 identity_cycle           | information_schema.character_data  |
 is_generated             | information_schema.character_data  |
 generation_expression    | information_schema.character_data  |
 is_updatable             | information_schema.character_data  |
View definition:
 SELECT current_database()::information_schema.sql_identifier AS table_catalog, nc.nspname::information_schema.sql_identifier AS table_schem
a, c.relname::information_schema.sql_identifier AS table_name, a.attname::information_schema.sql_identifier AS column_name, a.attnum::information_schema.cardinal_number AS ordinal_position, pg_get_expr(ad.adbin, ad.adrelid)::information_schema.character_data AS column_default,
        CASE
            WHEN a.attnotnull OR t.typtype = 'd'::"char" AND t.typnotnull THEN 'NO'::text
            ELSE 'YES'::text
        END::information_schema.character_data AS is_nullable,
        CASE
            WHEN t.typtype = 'd'::"char" THEN
            CASE
                WHEN bt.typelem <> 0::oid AND bt.typlen = (-1) THEN 'ARRAY'::text
                WHEN nbt.nspname = 'pg_catalog'::name THEN format_type(t.typbasetype, NULL::integer)
                ELSE 'USER-DEFINED'::text
            END
            ELSE
            CASE
                WHEN t.typelem <> 0::oid AND t.typlen = (-1) THEN 'ARRAY'::text
                WHEN nt.nspname = 'pg_catalog'::name THEN format_type(a.atttypid, NULL::integer)
                ELSE 'USER-DEFINED'::text
            END
        END::information_schema.character_data AS data_type, information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS character_maximum_length, information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS character_octet_length, information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS numeric_precision, information_schema._pg_numeric_precision_radix(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS numeric_precision_radix, information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS numeric_scale, information_schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*))::information_schema.cardinal_number AS datetime_precision, NULL::character varying::information_schema.character_data AS interval_type, NULL::character varying::information_schema.character_data AS interval_precision, NULL::character varying::information_schema.sql_identifier AS character_set_catalog, NULL::character varying::information_schema.sql_identifier AS character_set_schema, NULL::character varying::information_schema.sql_identifier AS character_set_name, NULL::character varying::information_schema.sql_identifier AS collation_catalog, NULL::character varying::information_schema.sql_identifier AS collation_schema, NULL::character varying::information_schema.sql_identifier AS collation_name,
        CASE
            WHEN t.typtype = 'd'::"char" THEN current_database()
            ELSE NULL::name
        END::information_schema.sql_identifier AS domain_catalog,
        CASE
            WHEN t.typtype = 'd'::"char" THEN nt.nspname
            ELSE NULL::name
        END::information_schema.sql_identifier AS domain_schema,
        CASE
            WHEN t.typtype = 'd'::"char" THEN t.typname
            ELSE NULL::name
        END::information_schema.sql_identifier AS domain_name, current_database()::information_schema.sql_identifier AS udt_catalog, COALESCE(nbt.nspname, nt.nspname)::information_schema.sql_identifier AS udt_schema, COALESCE(bt.typname, t.typname)::information_schema.sql_identifier AS udt_name, NULL::character varying::information_schema.sql_identifier AS scope_catalog, NULL::character varying::information_schema.sql_identifier AS scope_schema, NULL::character varying::information_schema.sql_identifier AS scope_name, NULL::integer::information_schema.cardinal_number AS maximum_cardinality, a.attnum::information_schema.sql_identifier AS dtd_identifier, 'NO'::character varying::information_schema.character_data AS is_self_referencing, 'NO'::character varying::information_schema.character_data AS is_identity, NULL::character varying::information_schema.character_data AS identity_generation, NULL::character varying::information_schema.character_data AS identity_start, NULL::character varying::information_schema.character_data AS identity_increment, NULL::character varying::information_schema.character_data AS identity_maximum, NULL::character varying::information_schema.character_data AS identity_minimum, NULL::character varying::information_schema.character_data AS identity_cycle, 'NEVER'::character varying::information_schema.character_data AS is_generated, NULL::character varying::information_schema.character_data AS generation_expression,
        CASE
            WHEN c.relkind = 'r'::"char" OR c.relkind = 'v'::"char" AND (EXISTS ( SELECT 1
               FROM pg_rewrite
              WHERE pg_rewrite.ev_class = c.oid AND pg_rewrite.ev_type = '2'::"char" AND pg_rewrite.is_instead)) AND (EXISTS ( SELECT 1
               FROM pg_rewrite
              WHERE pg_rewrite.ev_class = c.oid AND pg_rewrite.ev_type = '4'::"char" AND pg_rewrite.is_instead)) THEN 'YES'::text
            ELSE 'NO'::text
        END::information_schema.character_data AS is_updatable
   FROM pg_attribute a
   LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum, pg_class c, pg_namespace nc, pg_type t
   JOIN pg_namespace nt ON t.typnamespace = nt.oid
   LEFT JOIN (pg_type bt
   JOIN pg_namespace nbt ON bt.typnamespace = nbt.oid) ON t.typtype = 'd'::"char" AND t.typbasetype = bt.oid
  WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND NOT pg_is_other_temp_schema(nc.oid) AND a.attnum > 0 AND NOT a.attisdropped AND (c.relkind = ANY (ARRAY['r'::"char", 'v'::"char"])) AND (pg_has_role(c.relowner, 'USAGE'::text) OR has_column_privilege(c.oid, a.attnum, 'SELECT, INSERT, UPDATE, REFERENCES'::text));
catch’s picture

Version: 7.0 » 8.x-dev
Component: database system » postgresql database
Category: bug » task
Priority: Major » Normal
Issue tags: -PostgreSQL +Needs backport to D7

Moving to PostgreSQL driver, I'm not convinced this is a major bug in Drupal, MySQL used to have very slow information_schema performance which was fixed in more recent releases, so optimizing it in Drupal itself somehow comes under 'normal task' for me.

Also it needs to go into 8.x first then be backported.

bzrudi71’s picture

Component: postgresql database » postgresql db driver
Issue summary: View changes

Closed #2451723: Database::queryTableInformation optimization for PostgreSQL as a dup and added information here.

Database::queryTableInformation can be optimize, here is an example of the SQL generated by Database::queryTableInformation:

LOG:  statement: SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'variable' AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default::text LIKE '%nextval%'));
LOG:  duration: 14.278 ms

compared with an equivalent (I think) query against PostgreSQL system catalog tables:

LOG:  statement: SELECT pg_attribute.attname, pg_type.typname, pg_attrdef.adsrc
      FROM pg_namespace
      JOIN pg_class ON pg_namespace.oid = pg_class.relnamespace
      JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid
      JOIN pg_type ON pg_type.oid = pg_attribute.atttypid
      LEFT JOIN pg_attrdef ON pg_attrdef.oid   = pg_attribute.attrelid
                          AND pg_attrdef.adnum = pg_attribute.attnum
    WHERE pg_namespace.nspname = 'public'
      AND pg_class.relname = 'variable'
      AND pg_class.relkind IN ('r', 'v')
      AND (pg_type.typname = 'bytea' OR (pg_attribute.atttypmod <> -1 AND pg_attrdef.adsrc LIKE '%nextval'));
LOG:  duration: 2.249 ms

The problem is originally reported by nathanweeks.

bzrudi71’s picture

Issue tags: +PostgreSQL
bzrudi71’s picture

bzrudi71’s picture

Even so the results in #3 seems a bit outdated, because both queries finish within <1ms on a recent machine, the query against PostgreSQL system catalog tables is still around 8x faster than the current implementation. So seems worth to think about as we call queryTableInformation() very often!

bzrudi71’s picture

Unfortunately the query against the system catalogue doesn't return anything ;)

While this works:

d8=# SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'node' AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default::text LIKE 'nextval%'));
 column_name | data_type |          column_default           
-------------+-----------+-----------------------------------
 nid         | integer   | nextval('node_nid_seq'::regclass)
(1 row)

The catalogue query doesn't work:

d8=# SELECT pg_attribute.attname, pg_type.typname, pg_attrdef.adsrc
d8-#       FROM pg_namespace
d8-#       JOIN pg_class ON pg_namespace.oid = pg_class.relnamespace
d8-#       JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid
d8-#       JOIN pg_type ON pg_type.oid = pg_attribute.atttypid
d8-#       LEFT JOIN pg_attrdef ON pg_attrdef.oid   = pg_attribute.attrelid
d8-#                           AND pg_attrdef.adnum = pg_attribute.attnum
d8-#     WHERE pg_namespace.nspname = 'public'
d8-#       AND pg_class.relname = 'node'
d8-#       AND pg_class.relkind IN ('r', 'v')
d8-#       AND (pg_type.typname = 'bytea' OR (pg_attribute.atttypmod <> -1 AND pg_attrdef.adsrc LIKE 'nextval%'));
 attname | typname | adsrc 
---------+---------+-------
(0 rows)

Guess we need to have a second look on this...
BTW Doesn't even work with '%nextval%' and the check for views in AND pg_class.relkind IN ('r', 'v') seems obsolete.

bzrudi71’s picture

Tried a handful of alternative queries but always failed to gather *all* required information from the catalogues ;)
References:
pg-type
pg-class
pg-attribute
pg-attrdef

bzrudi71’s picture

Well, at least I got an working alternative here that gives some results. However, sadly this is only 3-4 times faster than the information schema query ;)
Any ideas to further speed up? Guess we should make a patch to actually see what happens :)

d8=# SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS data_type ,pg_attrdef.adsrc AS column_default
FROM  pg_attribute                                                            
LEFT JOIN pg_type ON pg_type.typrelid = pg_attribute.atttypid
LEFT JOIN pg_attrdef ON pg_attrdef.adrelid = pg_attribute.attrelid  AND pg_attrdef.adnum = pg_attribute.attnum
WHERE  pg_attribute.attnum > 0
AND NOT pg_attribute.attisdropped
AND pg_attribute.attrelid = 'public.node'::regclass 
AND (pg_type.typname = 'bytea' OR pg_attrdef.adsrc LIKE '%nextval%');
 column_name | data_type |          column_default           
-------------+-----------+-----------------------------------
 nid         | integer   | nextval('node_nid_seq'::regclass)
(1 row)

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.

mradcliffe’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Active » Needs review

Putting @bzrudi71's SQL into a patch and see what happens. I thought about if it would be possible to split into 2 distinct queries (bytea columns and sequence) to maybe improve the performance based on #9.

mradcliffe’s picture

daffie’s picture

Status: Needs review » Needs work

@mradcliffe: You should not remove the quotes around the .:table variable.

mradcliffe’s picture

@daffie: I don't think I am removing the quotes unless you mean from @bzrudi71's query. The placeholder should add the quotes from the bound parameter, right? If I added quotes around the placeholder it doesn't work.

In any case, typrelid is going to be 0 for any non-composite data types and thus the query is not returning any bytea columns. Maybe exclude pg_type table join? This seems to work locally.

daffie’s picture

@mradcliffe: If you take a look in the database the value is something like 'public.node'::regclass. And not public.node::regclass.

mradcliffe’s picture

But when I do this

            $sql .= "AND pg_attribute.attrelid = ':table'::regclass ";

or adding quotes in the parameters array it gives the following error:

2016-10-01 14:30:00 UTC [26976-5] drupal8@drupal8 ERROR:  schema "'public" does not exist at character 374
2016-10-01 14:30:00 UTC [26976-6] drupal8@drupal8 STATEMENT:  SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS data_type ,pg_attrdef.adsrc AS column_default FROM pg_attribute LEFT JOIN pg_attrdef ON pg_attrdef.adrelid = pg_attribute.attrelid  AND pg_attrdef.adnum = pg_attribute.attnum WHERE pg_attribute.attnum > 0 AND NOT pg_attribute.attisdropped AND pg_attribute.attrelid = '''public.cache_config'''::regclass AND (format_type(pg_attribute.atttypid, pg_attribute.atttypmod) = 'bytea' OR pg_attrdef.adsrc::text LIKE '%nextval%')
mradcliffe’s picture

Status: Needs review » Needs work

Flipping back to Needs Work.

pg_attribute is not updated yet? Maybe there is a commit/transaction issue? Or a caching issue?

mradcliffe’s picture

pgattrdef.adsrc is a historical record so won't be updated when the default value for a column is changed. The documentation suggests as such https://www.postgresql.org/docs/9.1/static/catalog-pg-attrdef.html.

Here's a patch that explains the query and makes that change.

mradcliffe’s picture

Issue summary: View changes

Let's write an issue summary too.

mradcliffe’s picture

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
@@ -123,11 +123,25 @@ public function queryTableInformation($table) {
+          $sql .= "LEFT JOIN pg_attrdef ON pg_attrdef.adrelid = pg_attribute.attrelid  AND pg_attrdef.adnum = pg_attribute.attnum ";

Extra space here: pg_attribute.attrelid AND pg_attrdef.adnum

daffie’s picture

The select statement looks great. Good find that you could remove the join to the pg_type table. I have a few small points:

  1. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
    @@ -123,11 +123,25 @@ public function queryTableInformation($table) {
                 ':default' => '%nextval%',
    

    Can we add the constant value direct in the statement.

  2. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
    @@ -123,11 +123,25 @@ public function queryTableInformation($table) {
    +            ':table' => $key,
    

    Can we rename :table to :key. With key being the combined schema.table variable.

mradcliffe’s picture

+1 for consistency in variables and placeholders.

I think we still need to keep the LIKE, but can search from the end. It's possible a sequence next value could be generated from other functions though I honestly doubt the use of wrapping nextval() in any math functions.

Edit: The reason we might not be able to do exact matching on the nextval is that the sequence/key may need to be hashed based on the length of the string.

daffie’s picture

@mradcliffe: If you think that it is that important to keep "%nextval%", then lets keep it. You have made the change:

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
@@ -134,13 +134,13 @@ public function queryTableInformation($table) {
-            ':default' => '%nextval%',
...
+            ':default' => 'nextval%',

Is this change a mistake? Or not?

mradcliffe’s picture

No, it is not a mistake. I meant to keep that change as all of Drupal's sequence entries begin with nextval( so we do not need to search for nextval in the middle of a string.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The patch looks great now.
The testbot with this patch is 10 minutes faster then without the patch. So the problem of this issue is addressed.
No extra tests are needed for this issue.

It get a RTBC from me.

Great work @mradcliffe.

bzrudi71’s picture

Nice research @mradcliffe - well done. I did a short review and all seems good to me, including the change for nextval%.

Thanks a ton and RTBC from my side too :)

alexpott’s picture

Wow the performance improvement due to this patch is impressive.

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
@@ -123,11 +123,25 @@ public function queryTableInformation($table) {
+          $sql .= "OR pg_attrdef.adsrc LIKE :default)";
...
+            ':default' => 'nextval%',

Why do we bother with value replacement when the the value is hardcoded?

bzrudi71’s picture

Re #28 Good point let's do that... I also testet at least the query itself on PostgreSQL 9.4 and 9.5 just to make sure it works even with latest versions.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

I asked for the same change in comment #22. So, for me this is RTBC again.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.47 KB
4.64 KB

It is great to see some effort going into making postgres faster by default since there is no reason it should be this much slower then MySQL. If this is a performance sensitive function then we should do more to avoid unnecessary queries. The patch attached does this - which I think is all in scope because we're doing the change for performance reasons.

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
@@ -123,11 +123,24 @@ public function queryTableInformation($table) {
+          $sql = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS data_type, pg_get_expr(pg_attrdef.adbin, pg_attribute.attrelid) AS column_default ";
+          $sql .= "FROM pg_attribute ";
+          $sql .= "LEFT JOIN pg_attrdef ON pg_attrdef.adrelid = pg_attribute.attrelid AND pg_attrdef.adnum = pg_attribute.attnum ";
+          $sql .= "WHERE pg_attribute.attnum > 0 ";
+          $sql .= "AND NOT pg_attribute.attisdropped ";
+          $sql .= "AND pg_attribute.attrelid = :key::regclass ";
+          $sql .= "AND (format_type(pg_attribute.atttypid, pg_attribute.atttypmod) = 'bytea' ";
+          $sql .= "OR pg_attrdef.adsrc LIKE 'nextval%')";

Let's use nowdoc syntax - all this concatenation is unnecessary and ending with the empty space a bit ugly.

mradcliffe’s picture

  1. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
    @@ -149,6 +141,13 @@ public function queryTableInformation($table) {
    +      if (empty($result)) {
    +        return $table_information;
    +      }
    

    Interested to see how this will work out on the tests.

    Nice find.

  2. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
    @@ -167,6 +166,19 @@ public function queryTableInformation($table) {
    +    if (!isset($this->tempNamespaceName)) {
    +      $this->tempNamespaceName = $this->connection->query('SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema()')->fetchField();
    +    }
    

    Nice. I think this should work out and should clean up disk usage since we are probably creating lots of temporary schemas each connection.

mradcliffe’s picture

1 minute off the 5.5 run, and 5 minutes off of the 7.x run. That's fairly significant. That probably means that the PHP changes in the driver are more optimized with the patch in #31 and the temporary schema change in #31 is consistent.

RTBC for me. I'll let someone else confirm and change it to get more eyes on the patch.

mradcliffe’s picture

Issue summary: View changes

Updated issue summary.

bzrudi71’s picture

Status: Needs review » Reviewed & tested by the community

Wow! Another 5 min speed improvement for the PHP7 testbot, impressive :) I don't find anything wrong with the patch from alexpott and it's in scope of this issue, so let's get it in - RTBC.

Thanks @alexpott for the nice patch improvements!

daffie’s picture

+1 for RTBC. Thanks @alexpott for all your help!

  • catch committed 868639c on 8.3.x
    Issue #1079762 by mradcliffe, bzrudi71: DatabaseSchema_pgsql::...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x, thanks!

  • catch committed 7e98e88 on 8.3.x
    Revert "Issue #1079762 by mradcliffe, bzrudi71: DatabaseSchema_pgsql::...
  • catch committed e2d0405 on 8.3.x
    Issue #1079762 by mradcliffe, bzrudi71, alexpott, daffie, ogi:...
mradcliffe’s picture

Version: 8.3.x-dev » 7.x-dev
Status: Fixed » Needs review
FileSize
3.83 KB

Here's a back port patch for Drupal 7.

It looks like everything is supported for those old versions of PostgreSQL.

Status: Needs review » Needs work

The last submitted patch, 40: 1079762-40.patch, failed testing.

mradcliffe’s picture

Status: Needs work » Needs review

Bad test bot.

alexpott’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs review » Fixed

@mradcliffe the new backport policy is to open a new issue and related it to this one - see https://www.drupal.org/core/backport-policy

mradcliffe’s picture

Issue tags: -Needs backport to D7

Oh, I didn't realize the policy changed. Thank you, @alexpott.

Follow-up issue created for Drupal 7: #2823488: Backport DatabaseSchema_pgsql::queryTableInformation() improvements.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.