]> git.mxchange.org Git - friendica.git/commitdiff
Faster count queries when updating the info about current node
authorEsko Arajärvi <esko.arajarvi@solita.fi>
Tue, 4 Feb 2025 16:46:06 +0000 (18:46 +0200)
committerEsko Arajärvi <esko.arajarvi@solita.fi>
Tue, 4 Feb 2025 17:47:31 +0000 (19:47 +0200)
MySQL optimiser seems to prefer a full table scan of `post-user`
table in the count query mentioned in issue #14763. When the origin
and deleted columns are added to the index, the IN-query part of
the query can be done with index-only scan, which is much faster.

Adding the columns in the order

    uri-id, origin, deleted

allows some other queries to also use it when checking
for uri-id and origin.

Fixes #14763

database.sql
doc/database/db_post-user.md
static/dbstructure.config.php

index f12af1ef232e878b84e9b178d4dcd4f067d7b662..37bb53a68dd51699b9db482199896a4b93a5fa39 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2025.02-dev (Interrupted Fern)
--- DB_UPDATE_VERSION 1576
+-- DB_UPDATE_VERSION 1577
 -- ------------------------------------------
 
 
@@ -1609,7 +1609,7 @@ CREATE TABLE IF NOT EXISTS `post-user` (
        `psid` int unsigned COMMENT 'ID of the permission set of this post',
         PRIMARY KEY(`id`),
         UNIQUE INDEX `uid_uri-id` (`uid`,`uri-id`),
-        INDEX `uri-id` (`uri-id`),
+        INDEX `uri-id_origin_deleted` (`uri-id`,`origin`,`deleted`),
         INDEX `parent-uri-id` (`parent-uri-id`),
         INDEX `thr-parent-id` (`thr-parent-id`),
         INDEX `external-id` (`external-id`),
index f702502bf27ae466ef06c182fd57bc96be8faf2f..41e077595d3468033e75627203d1d59ad4b89892 100644 (file)
@@ -44,31 +44,31 @@ Fields
 Indexes
 ------------
 
-| Name                 | Fields                  |
-| -------------------- | ----------------------- |
-| PRIMARY              | id                      |
-| uid_uri-id           | UNIQUE, uid, uri-id     |
-| uri-id               | uri-id                  |
-| parent-uri-id        | parent-uri-id           |
-| thr-parent-id        | thr-parent-id           |
-| external-id          | external-id             |
-| replies-id           | replies-id              |
-| owner-id             | owner-id                |
-| author-id            | author-id               |
-| causer-id            | causer-id               |
-| vid                  | vid                     |
-| contact-id           | contact-id              |
-| event-id             | event-id                |
-| psid                 | psid                    |
-| author-id_uid        | author-id, uid          |
-| author-id_created    | author-id, created      |
-| owner-id_created     | owner-id, created       |
-| parent-uri-id_uid    | parent-uri-id, uid      |
-| uid_wall_received    | uid, wall, received     |
-| uid_contactid        | uid, contact-id         |
-| uid_unseen_contactid | uid, unseen, contact-id |
-| uid_unseen           | uid, unseen             |
-| uid_hidden_uri-id    | uid, hidden, uri-id     |
+| Name                  | Fields                  |
+|-----------------------| ----------------------- |
+| PRIMARY               | id                      |
+| uid_uri-id            | UNIQUE, uid, uri-id     |
+| uri-id_origin_deleted | uri-id, origin, deleted |
+| parent-uri-id         | parent-uri-id           |
+| thr-parent-id         | thr-parent-id           |
+| external-id           | external-id             |
+| replies-id            | replies-id              |
+| owner-id              | owner-id                |
+| author-id             | author-id               |
+| causer-id             | causer-id               |
+| vid                   | vid                     |
+| contact-id            | contact-id              |
+| event-id              | event-id                |
+| psid                  | psid                    |
+| author-id_uid         | author-id, uid          |
+| author-id_created     | author-id, created      |
+| owner-id_created      | owner-id, created       |
+| parent-uri-id_uid     | parent-uri-id, uid      |
+| uid_wall_received     | uid, wall, received     |
+| uid_contactid         | uid, contact-id         |
+| uid_unseen_contactid  | uid, unseen, contact-id |
+| uid_unseen            | uid, unseen             |
+| uid_hidden_uri-id     | uid, hidden, uri-id     |
 
 Foreign Keys
 ------------
index 55ebbad6fd20070ac248107043cf54e093997be2..847b0e9600499f8bb697fde2e5526caf01afb5f5 100644 (file)
@@ -44,7 +44,7 @@ use Friendica\Database\DBA;
 
 // This file is required several times during the test in DbaDefinition which justifies this condition
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1576);
+       define('DB_UPDATE_VERSION', 1577);
 }
 
 return [
@@ -1604,7 +1604,7 @@ return [
                "indexes" => [
                        "PRIMARY" => ["id"],
                        "uid_uri-id" => ["UNIQUE", "uid", "uri-id"],
-                       "uri-id" => ["uri-id"],
+                       "uri-id_origin_deleted" => ["uri-id", "origin", "deleted"],
                        "parent-uri-id" => ["parent-uri-id"],
                        "thr-parent-id" => ["thr-parent-id"],
                        "external-id" => ["external-id"],