Структуры таблиц:
CREATE TABLE `ebay_items` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`item_id` bigint(20) NOT NULL,
`item_url` text COLLATE utf8mb4_unicode_ci NOT NULL,
`title` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_low` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_mid` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_max` text COLLATE utf8mb4_unicode_ci NOT NULL,
`price` decimal(10,2) NOT NULL,
`price_with_sign` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`shipping_price` decimal(10,2) NOT NULL,
`shipping_with_sign` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`quantity` int(11) NOT NULL,
`brand` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`model` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`upc` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`variation_array` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`image_array` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`category_array` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`step_number` int(11) NOT NULL,
`archived` int(11) NOT NULL,
`archived_number` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5765 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `amazon_items` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`asin` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`related_ebay_item_id` bigint(20) NOT NULL,
`item_url` text COLLATE utf8mb4_unicode_ci NOT NULL,
`title` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_low` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_mid` text COLLATE utf8mb4_unicode_ci NOT NULL,
`main_image_max` text COLLATE utf8mb4_unicode_ci NOT NULL,
`buy_box_price` decimal(10,2) NOT NULL,
`buy_box_price_with_sign` text COLLATE utf8mb4_unicode_ci NOT NULL,
`lowest_other_sellers_price` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`other_number_of_seller` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`variation_array` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`category_array` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`step_number` int(11) NOT NULL,
`archived` int(11) NOT NULL,
`archived_number` int(11) NOT NULL,
`status` int(11) NOT NULL DEFAULT '0',
`user_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7398 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Create Table
CREATE TABLE `item_attributes` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`amazon_id` bigint(20) NOT NULL,
`sku` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`quantity` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currency` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`list_price` decimal(10,2) DEFAULT NULL,
`min_price` decimal(10,2) DEFAULT NULL,
`max_price` decimal(10,2) DEFAULT NULL,
`estimated_profit` decimal(10,2) DEFAULT NULL,
`added_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`refresh_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` int(11) NOT NULL,
`status` smallint(6) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `import_items_logs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ebay_id` int(11) NOT NULL,
`amazon_id` int(11) NOT NULL,
`tag` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`status` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
SELECT ei.id
, ei.item_id
, ei.item_url
, ei.title
, ei.main_image_low
, ei.price
, ei.price_with_sign
, ei.shipping_price
, ei.shipping_with_sign
, ei.quantity
, ei.brand
, ei.model
, ei.upc
, ei.step_number
, ei.archived
, ei.archived_number
, ei.user_id
, ei.created_at
, ei.updated_at
, ai.id amazon_id
, ai.asin
, ai.item_url amazon_item_url
, ai.title amazon_title
, ai.main_image_low amazon_low_image
, ai.buy_box_price_with_sign
, ai.lowest_other_sellers_price
, ai.other_number_of_seller
, ai.category_array
, ai.status amazon_status
, ia.sku
, ia.list_price
, ia.min_price
, ia.max_price
, ia.estimated_profit
, ia.status attr_status
, ia.added_time attr_added_time
, ia.refresh_time attr_refresh_time
, l.status import_status
, l.tag import_tag
FROM ebay_items ei
JOIN amazon_items ai
ON ai.related_ebay_item_id = ei.id
LEFT
JOIN item_attributes ia
ON ia.amazon_id = ai.id
LEFT
JOIN import_items_logs l
ON l.ebay_id = ei.id
WHERE ei.user_id = 1
AND ei.archived =2
GROUP
BY ei.id
Я пытаюсь получить элемент и дополнительные сведения, которые находятся в отдельных таблицах
Есть 4 таблицы ebay_items, amazon_items, item_attributes, import_items_logs Это то, что я хочу в результате,
ebay_items и amazon_items должны совпадать (ebay_items. id = amazon_items.related_ebay_item_id)
также item_attributes (amazon_items.id = item_attributes.amazon_id) и import_items_logs (ebay_items.id = import_items_logs.ebay_id) 10 записей необходимы, если есть какие-либо записи 1023 *
Это мой запрос, когда я бегал по локальной сети, это занимает 50 + se c или amazon server, это занимает 12se c до fini sh. Что не так я делаю здесь. Всего записей 2600. Я не знаю, почему это слишком медленно
Запрос Объяснить
id select_type table type possible_keys key key_len ref rows Extra
------ ----------- ------ ------ ------------- ------- ------- --------------------------------------- ------ --------------------------------------------------------
1 SIMPLE ai ALL (NULL) (NULL) (NULL) (NULL) 4277 Using temporary; Using filesort
1 SIMPLE ei eq_ref PRIMARY PRIMARY 8 other_rp-tool-2.ai.related_ebay_item_id 1 Using where
1 SIMPLE ia ALL (NULL) (NULL) (NULL) (NULL) 3134 Using where; Using join buffer (flat, BNL join)
1 SIMPLE l ALL (NULL) (NULL) (NULL) (NULL) 6076 Using where; Using join buffer (incremental, BNL join) ```