I have the following query which needs to run up to 40-50 times on some pages.
SELECT lid, dest, rebuild FROM {store_links_link}
WHERE source = :url;
Source column is URLs and the problem is that some values of the urls/source are really long and it incredibly slows down the query.
I know that it should be fixed on the application level but what changes can be made in Mysql configuration to speed up this query?
store_links_link table has over 50,000 links and some can be quite long. I have query cache enabled which helps to some extent. Previously, the application ran on MySql 5.6 which was able to cope well but Mariadb 10 doesn't cope at all.
Output for SHOW CREATE TABLE
:
CREATE TABLE store_links_link
(
lid char(32) NOT NULL COMMENT 'Link ID using MD5, also act as cloaked link.',
accid int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Account ID from affiliate_links_account.accid.',
SOURCE varchar(5000) DEFAULT NULL,
dest text NOT NULL COMMENT 'Converted link URL with ID info.',
rebuild tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT 'Whether the account link should be rebuilt.',
COUNT int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Click count for cloaked link.',
nid varchar(255) DEFAULT NULL COMMENT 'Node ID',
created timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'creation and upadtion time of source/dest link',
PRIMARY KEY (lid),
KEY affiliate_urls (source(768))
) ENGINE=InnoDB DEFAULT
CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='URL link conversion table.'
SHOW CREATE TABLE
. How long is "really long"? Are you usingVARCHAR
? OrTEXT
? Isurl
indexed?url
. Consider how you'd restructure data so that this isn't run 40-50 times per page.