mysql创建排序索引使查询变慢

时间:2021-02-28 14:59:26

标签: mysql sorting indexing

我们有一个视图表,视图的查询粘贴在下面。问题是,每当我们尝试查询项目时,我们的数据库都会开始制作排序索引,这使得我们的响应速度非常缓慢。

CREATE VIEW items_view AS
SELECT item_detail.*, item.name, item.description, item.thumbnail_url, item.large_image_url, item.ios_url, item.android_url, item.vr_url, item.vr_updated_url, item.webgl_url, item.video_url, item.quest_url,
item.is_transferable, item.ip_id, item.brand_id, item.edition_id, item.currency_id, item.category_id, item.rarity_id, item.type_id, item.asset_id, item.artist_id, item.art_collection_id,
IFNULL(item.variation_id, 0) AS variation_id,
item.series_id, item.set_id, item.is_tradable, item.number_minted, ip.name AS ip_name, brand.name As brand_name, brand.value AS brand_image,
edition.name AS edition_name, type.name As type_name, artist.name AS artist_name, art_collection.name AS art_collection_name,
IFNULL(variation.name, '') As variation_name, variation.value AS variation_value, category.name As category_name, asset.name AS asset_name, asset.value AS asset_image,
rarity.name As rarity_name, currency.symbol, currency.code AS currency_code, currency.name AS currency_name, series.name AS series_name, sets.name AS set_name,
CONCAT(users.first_name, ' ' ,users.last_name) as owner_name, users.username AS owner_username, users.is_public_inventory, users.role, users.pub_key,
auctions.id as auction_id, auctions.expire_at as auction_expire_at, max(ab.bid_amount) AS highest_bid_amount, IF(COUNT(auctions.id) > 0 AND !auctions.is_completed AND !auctions.is_deleted
, true, false) AS is_auction, auctions.start_amount AS auction_start_amount, auctions.reserved_amount AS auction_reserved_amount, auctions.buy_now_amount AS auction_buy_now_amount,
auctions.created_at as auction_created_at, auctions.status AS auction_status, auctions.is_extended AS auction_extended, TIMESTAMPDIFF(SECOND, now(), auctions.expire_at) AS auction_expire_seconds FROM item
LEFT JOIN base_lookup AS ip ON item.ip_id = ip.id
LEFT JOIN base_lookup AS brand ON item.brand_id = brand.id
LEFT JOIN base_lookup AS edition ON item.edition_id = edition.id
LEFT JOIN base_lookup AS category ON item.category_id = category.id
LEFT JOIN base_lookup AS type ON item.type_id = type.id
LEFT JOIN base_lookup AS variation ON item.variation_id = variation.id
LEFT JOIN base_lookup AS rarity ON item.rarity_id = rarity.id
LEFT JOIN base_lookup AS series ON item.series_id = series.id
LEFT JOIN base_lookup AS sets ON item.set_id = sets.id
LEFT JOIN base_lookup AS asset ON item.asset_id = asset.id
LEFT JOIN base_lookup AS artist ON item.artist_id = artist.id
LEFT JOIN base_lookup AS art_collection ON item.art_collection_id = art_collection.id
INNER JOIN item_detail ON item.id = item_detail.parent_id
INNER JOIN users ON users.id = item_detail.owner_id
LEFT JOIN currency ON currency.id = item.currency_id
LEFT JOIN auctions on (item_detail.id = auctions.item_detail_id AND auctions.is_deleted = 0 AND auctions.is_completed = 0)
LEFT JOIN auction_bidding ab on auctions.id = ab.auction_id
WHERE item_detail.is_active = 1
group by item_detail.id
order by item_detail.id;

我们在此 items_view 上执行的查询之一卡在制作排序索引中

SELECT 
  `id`, `code`, `name`, `large_image_url`, 
  `thumbnail_url`, `medium_thumbnail_url`, `symbol`, `ip_name`, `owner_id`, 
  `auction_id`, `is_auction`, `highest_bid_amount`, `auction_expire_at`, 
  `auction_start_amount`, `enable_sale`, `owner_name`, `role`, `amount`, 
  `auction_expire_seconds`, `rarity_name`, `ip_content`, `asset_content` 
FROM `items_view` AS `items_view` 
WHERE `items_view`.`transaction_hash` IS NOT NULL AND 
  `items_view`.`lobby_name` = 'live' AND 
  `items_view`.`is_tradable` = 1 AND 
  `items_view`.`is_transferring` = 0 AND 
  `items_view`.`is_locked` = 0 AND 
  `items_view`.`enable_sale` = true AND 
  `items_view`.`is_auction` = 0 
ORDER BY `items_view`.`item_order` ASC LIMIT 24, 24;

任何人都可以提出任何建议我们在这里做错了什么!

编辑: 解释针对上述查询运行的链接 link to csv

0 个答案:

没有答案