我有一个产品表,如下所示
CREATE TABLE `tbl_store_products` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`store_id` int(10) unsigned NOT NULL,
`is_featured` tinyint(1) unsigned NOT NULL DEFAULT '0',
`title` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`description` text COLLATE utf8mb4_unicode_ci NOT NULL,
`promotion_sale` tinyint(1) unsigned NOT NULL DEFAULT '0',
`current_price` int(10) unsigned NOT NULL,
`original_price` int(10) unsigned NOT NULL,
`parent_category` int(10) unsigned NOT NULL,
`sub_parent_category` int(10) unsigned NOT NULL,
`child_category` int(10) unsigned NOT NULL,
`instock_quantity` int(10) unsigned NOT NULL,
`sold_quantity` int(10) unsigned NOT NULL DEFAULT '0',
`list_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`reviewed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `store_id` (`store_id`),
KEY `parent_cat` (`parent_category`),
KEY `sub_parent_cat` (`sub_parent_category`),
KEY `category` (`child_category`),
FULLTEXT KEY `product_title` (`title`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
如你所见,我有5个指数。其中3个是产品类别。我这样做是为了使产品在父类别,子类别和子类别中快速可用。类别深度始终为3。
例如,如果标题为女性时尚高跟鞋的产品位于Fashion > Women Shoes > Heels
目前,当用户点击面包屑
中的任何链接时,我正在使用这些查询来获取产品//Heels category id = 10
SELECT title, current_price, description FROM tbl_store_products WHERE category = 10
或
//Women Shoes category id = 8
SELECT title, current_price, description FROM tbl_store_products WHERE sub_parent_category = 8
或
//Fashion category id = 4
SELECT title, current_price, description FROM tbl_store_products WHERE parent_category = 4
我发现各级别的产品都很好。但我觉得我创造了太多指数。任何人都可以建议我这样做的更好方法。如果有人能告诉我关于我桌子的其他问题的其他建议,我将不胜感激。谢谢!