Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

PLATFORM-1914: update querycache schema for new wikis #9863

Merged
merged 1 commit into from
Mar 2, 2016

Conversation

macbre
Copy link
Contributor

@macbre macbre commented Mar 1, 2016

PLATFORM-1914

Due to a MySQL 5.6 bug InnoDB tables that do not have primary key defined has problems with replication of heavy transactions (with tens of thousands of rows involved).

We noticed this behavior during updateSpecialPages.php script run which performs heavy (DELETE + INSERT queries) operations on querycache table. This was quite visible when ruvlab wiki was processed - the maintenance script was performing a transaction with delete and insert of 75k rows causing huge lag on c1 cluster.

querycache table indeed lacks a primary key, so let's add it for new wikis.

Before:

CREATE TABLE `querycache` (
  `qc_type` varbinary(32) NOT NULL,
  `qc_value` int(10) unsigned NOT NULL DEFAULT '0',
  `qc_namespace` int(11) NOT NULL DEFAULT '0',
  `qc_title` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
  KEY `qc_type` (`qc_type`,`qc_value`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

+--------------+------------------+------+-----+---------+-------+
| Field        | Type             | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| qc_type      | varbinary(32)    | NO   | MUL | NULL    |       |
| qc_value     | int(10) unsigned | NO   |     | 0       |       |
| qc_namespace | int(11)          | NO   |     | 0       |       |
| qc_title     | varchar(255)     | NO   |     |         |       |
+--------------+------------------+------+-----+---------+-------+

After:

CREATE TABLE `querycache` (
  `qc_type` varbinary(32) NOT NULL,
  `qc_value` int(10) unsigned NOT NULL DEFAULT '0',
  `qc_namespace` int(11) NOT NULL DEFAULT '0',
  `qc_title` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
  UNIQUE KEY `qc_type_value_ns_title` (`qc_type`,`qc_value`,`qc_namespace`,`qc_title`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

+--------------+------------------+------+-----+---------+-------+
| Field        | Type             | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| qc_type      | varbinary(32)    | NO   | PRI | NULL    |       |
| qc_value     | int(10) unsigned | NO   | PRI | 0       |       |
| qc_namespace | int(11)          | NO   | PRI | 0       |       |
| qc_title     | varchar(255)     | NO   | PRI |         |       |
+--------------+------------------+------+-----+---------+-------+

@drozdo / @wladekb / @adamkarminski

@macbre macbre closed this Mar 1, 2016
@macbre macbre reopened this Mar 1, 2016
@macbre
Copy link
Contributor Author

macbre commented Mar 1, 2016

This simply can't be related to a SQL schema file change.

VideoPageToolAssetTest::testCRUDAsset with data set #0 ('VideoPageToolAssetFeatured', 1, array('test_title', 'Test Display Title', 'This is a test description', 'Alternate Thumb Title'))
Not able to load saved asset
Failed asserting that null matches expected 15463.

@wladekb
Copy link

wladekb commented Mar 1, 2016

lgtm, only wondering how big the index will be but it's unlikely to get us into big trouble

macbre added a commit that referenced this pull request Mar 2, 2016
…schema-for-new-wikis

PLATFORM-1914: update querycache schema for new wikis
@macbre macbre merged commit 5e728dc into dev Mar 2, 2016
@macbre macbre deleted the PLATFORM-1914-querycache-updated-schema-for-new-wikis branch March 2, 2016 09:54
@macbre
Copy link
Contributor Author

macbre commented Mar 2, 2016

@wladekb - take a look at the last comment in PLATFORM-1914

Due to the way InnoDB handles primary key and data storage we actually improve the data and index size (for lyricwiki the current data + index size for querycache is just 37% when compared with the size before the fix).

Table data in InnoDB are stored in the index structure of primary key (explicit or implicit). So, primary key is data and there is no need to report its size as (secondary) index size.

@wladekb
Copy link

wladekb commented Mar 2, 2016

Unbelievable :) Thanks for the research.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants