SELECT 
  cscart_products.*, 
  cscart_product_descriptions.*, 
  MIN(
    IF(
      cscart_product_prices.percentage_discount = 0, 
      cscart_product_prices.price, 
      cscart_product_prices.price - (
        cscart_product_prices.price * cscart_product_prices.percentage_discount
      )/ 100
    )
  ) as price, 
  GROUP_CONCAT(
    CASE WHEN (
      cscart_products_categories.link_type = 'M'
    ) THEN CONCAT(
      cscart_products_categories.category_id, 
      'M'
    ) ELSE cscart_products_categories.category_id END 
    ORDER BY 
      cscart_categories.storefront_id IN (0, 1) DESC, 
      (
        cscart_products_categories.link_type = 'M'
      ) DESC, 
      cscart_products_categories.category_position ASC, 
      cscart_products_categories.category_id ASC
  ) as category_ids, 
  GROUP_CONCAT(
    CASE WHEN (
      cscart_products_tag_categories.link_type = 'M'
    ) THEN CONCAT(
      cscart_products_tag_categories.category_id, 
      'M'
    ) ELSE cscart_products_tag_categories.category_id END 
    ORDER BY 
      cscart_categories.storefront_id IN (0, 1) DESC, 
      (
        cscart_products_tag_categories.link_type = 'M'
      ) DESC, 
      cscart_products_tag_categories.category_position ASC, 
      cscart_products_tag_categories.category_id ASC
  ) as category_tag_ids, 
  popularity.total as popularity, 
  companies.company as company_name, 
  cscart_product_sales.amount as sales_amount, 
  cscart_seo_names.name as seo_name, 
  cscart_seo_names.path as seo_path, 
  cscart_discussion.type as discussion_type, 
  cscart_product_review_prepared_data.average_rating average_rating, 
  cscart_product_review_prepared_data.reviews_count product_reviews_count, 
  ps.sold as sold 
FROM 
  cscart_products 
  LEFT JOIN cscart_product_prices ON cscart_product_prices.product_id = cscart_products.product_id 
  AND cscart_product_prices.lower_limit = 1 
  AND cscart_product_prices.usergroup_id IN (0, 0, 1) 
  LEFT JOIN cscart_product_descriptions ON cscart_product_descriptions.product_id = cscart_products.product_id 
  AND cscart_product_descriptions.lang_code = 'vi' 
  LEFT JOIN cscart_companies as companies ON companies.company_id = cscart_products.company_id 
  INNER JOIN cscart_products_categories ON cscart_products_categories.product_id = cscart_products.product_id 
  LEFT JOIN cscart_products_tag_categories ON cscart_products_tag_categories.product_id = cscart_products.product_id 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND (
    cscart_products.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_products.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_products.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
  AND cscart_products.status IN ('A', 'H') 
  LEFT JOIN cscart_product_popularity as popularity ON popularity.product_id = cscart_products.product_id 
  LEFT JOIN cscart_product_sales ON cscart_product_sales.product_id = cscart_products.product_id 
  AND cscart_product_sales.category_id = 149 
  LEFT JOIN cscart_seo_names ON cscart_seo_names.object_id = 40450 
  AND cscart_seo_names.type = 'p' 
  AND cscart_seo_names.dispatch = '' 
  AND cscart_seo_names.lang_code = 'vi' 
  LEFT JOIN cscart_discussion ON cscart_discussion.object_id = cscart_products.product_id 
  AND cscart_discussion.object_type = 'P' 
  LEFT JOIN cscart_product_review_prepared_data ON cscart_product_review_prepared_data.product_id = cscart_products.product_id 
  AND cscart_product_review_prepared_data.storefront_id = 0 
  LEFT JOIN cscart_product_sold ps ON cscart_products.product_id = ps.product_id 
WHERE 
  cscart_products.product_id = 40450 
  AND (
    companies.status IN ('A') 
    OR cscart_products.company_id = 0
  ) 
GROUP BY 
  cscart_products.product_id

Query time 0.06807

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "table": {
          "table_name": "cscart_products",
          "access_type": "const",
          "possible_keys": ["PRIMARY", "status"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 1,
          "filtered": 100
        }
      },
      {
        "table": {
          "table_name": "popularity",
          "access_type": "const",
          "possible_keys": ["PRIMARY", "total"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 1,
          "filtered": 100
        }
      },
      {
        "table": {
          "table_name": "cscart_product_sales",
          "access_type": "const",
          "possible_keys": ["PRIMARY", "pa"],
          "key": "PRIMARY",
          "key_length": "6",
          "used_key_parts": ["category_id", "product_id"],
          "ref": ["const", "const"],
          "rows": 1,
          "filtered": 100
        }
      },
      {
        "table": {
          "table_name": "cscart_product_prices",
          "access_type": "ref",
          "possible_keys": [
            "usergroup",
            "product_id",
            "lower_limit",
            "usergroup_id"
          ],
          "key": "product_id",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_product_prices.lower_limit = 1 and cscart_product_prices.usergroup_id in (0,0,1))"
        }
      },
      {
        "table": {
          "table_name": "cscart_product_descriptions",
          "access_type": "const",
          "possible_keys": ["PRIMARY", "product_id"],
          "key": "PRIMARY",
          "key_length": "11",
          "used_key_parts": ["product_id", "lang_code"],
          "ref": ["const", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_product_descriptions.lang_code = 'vi')"
        }
      },
      {
        "table": {
          "table_name": "companies",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "4",
          "used_key_parts": ["company_id"],
          "ref": ["const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(companies.`status` = 'A')"
        }
      },
      {
        "table": {
          "table_name": "cscart_products_categories",
          "access_type": "ref",
          "possible_keys": ["PRIMARY", "pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 3,
          "filtered": 100
        }
      },
      {
        "table": {
          "table_name": "cscart_categories",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "c_status", "p_category_id"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["category_id"],
          "ref": ["dev_db.cscart_products_categories.category_id"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "cscart_categories.storefront_id in (0,1) and (cscart_categories.usergroup_ids = '' or find_in_set(0,cscart_categories.usergroup_ids) or find_in_set(1,cscart_categories.usergroup_ids)) and cscart_categories.`status` in ('A','H')"
        }
      },
      {
        "table": {
          "table_name": "cscart_products_tag_categories",
          "access_type": "ref",
          "possible_keys": ["pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 16,
          "filtered": 100
        }
      },
      {
        "table": {
          "table_name": "cscart_seo_names",
          "access_type": "ref",
          "possible_keys": ["PRIMARY", "dispatch"],
          "key": "PRIMARY",
          "key_length": "206",
          "used_key_parts": ["object_id", "type", "dispatch", "lang_code"],
          "ref": ["const", "const", "const", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_seo_names.`type` = 'p' and cscart_seo_names.dispatch = '' and cscart_seo_names.lang_code = 'vi')"
        }
      },
      {
        "table": {
          "table_name": "cscart_discussion",
          "access_type": "const",
          "possible_keys": ["object_id"],
          "key": "object_id",
          "key_length": "6",
          "used_key_parts": ["object_id", "object_type"],
          "ref": ["const", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_discussion.object_type = 'P')"
        }
      },
      {
        "table": {
          "table_name": "cscart_product_review_prepared_data",
          "access_type": "const",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "7",
          "used_key_parts": ["product_id", "storefront_id"],
          "ref": ["const", "const"],
          "rows": 1,
          "filtered": 100
        }
      },
      {
        "block-nl-join": {
          "table": {
            "table_name": "<derived2>",
            "access_type": "ALL",
            "rows": 12545,
            "filtered": 100,
            "attached_condition": "ps.product_id = 40450"
          },
          "buffer_type": "flat",
          "buffer_size": "256Kb",
          "join_type": "BNL",
          "attached_condition": "trigcond(ps.product_id = 40450)",
          "materialized": {
            "query_block": {
              "select_id": 2,
              "filesort": {
                "sort_key": "count(cscart_order_details.product_id) desc",
                "temporary_table": {
                  "nested_loop": [
                    {
                      "table": {
                        "table_name": "cscart_order_details",
                        "access_type": "index",
                        "key": "o_k",
                        "key_length": "6",
                        "used_key_parts": ["order_id", "product_id"],
                        "rows": 12545,
                        "filtered": 100,
                        "using_index": true
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    ]
  }
}

Result

product_id product_code product_type status company_id list_price amount weight length width height shipping_freight low_avail_limit timestamp updated_timestamp usergroup_ids is_edp edp_shipping unlimited_download tracking free_shipping zero_price_action is_pbp is_op is_oper is_returnable return_period is_make_to_order make_period avail_since out_of_stock_actions localization min_qty max_qty qty_step list_qty_count tax_ids age_verification age_limit options_type exceptions_type details_layout shipping_params facebook_obj_type parent_product_id buy_now_url is_stock_split_by_warehouses is_fragile lang_code product shortname short_description full_description meta_keywords meta_description search_words page_title age_warning_message promo_text specification special_note punch_line selection chus_note about_brand why_chus purchasing_notice note_from_brand is_sync_seo_url price category_ids category_tag_ids popularity company_name sales_amount seo_name seo_path discussion_type average_rating product_reviews_count sold
40450 10018_92 P A 126 0 996 400.000 0 0 0 0.00 0 1682414382 1727144523 0 N N N B N R N N N Y 10 Y 7 - 10 0 N 1 0 0 0 N 0 P F default a:5:{s:16:"min_items_in_box";i:1;s:16:"max_items_in_box";i:1;s:10:"box_length";i:25;s:9:"box_width";i:15;s:10:"box_height";i:10;} 0 N N vi Glow, Móc Chìa Khóa Da Vẽ Tay, BST MCK Light, Da Bò Cao Cấp, Móc Khóa Vẽ Tay, Quà Tặng Thủ Công, Quà Tặng Nghệ Thuật, Quà Tặng Cá Nhân Hóa <p>Móc Chìa Khóa Da Vẽ Tay Glow là món quà độc đáo và ý nghĩa dành cho bạn bè, người thân hay chính bản thân bạn. "Glow" nằm trong BST MCK Light lấy cảm hứng từ những tia sáng lung linh, tượng trưng cho sự tự chủ và nguồn cảm hứng sáng tạo. Mỗi đường nét, chi tiết đều được Đỏ vẽ tay tỉ mỉ, đảm bảo sự độc đáo và tinh tế trong từng sản phẩm. Chất liệu da bò thật 100% mang đến độ bền bỉ, mềm mại và cảm giác sang trọng khi sử dụng.</p> <p> </p> <h3><em>Cách để đặt móc khóa mang dấu ấn cá nhân của bạn hoặc để làm quà tặng: </em></h3> <p> </p> <p>- Chọn Add-on khắc tên theo yêu cầu </p> <p> </p> <p>- Ghi tên muốn khắc trên móc chìa khóa vào ô "Lưu ý từ khách hàng". Giới hạn ký tự từ 5-7 ký tự </p> <p> </p> <p><em>Lưu ý: Khách hàng lưu ý thời gian đặt khằc tên sẽ tầm 7-10 ngày </em></p> , “Glow” Hand-drawn Leather Keychain, MCK Light Collection, Personalized Keychain, Cowhide Leather, Gift Keychain, Gift For Him/Her, Personalized Gifts “Glow” Hand-drawn Leather Keychain, MCK Light Collection <p>- Kích thước: 8 x 4cm</p> <p> </p> <p>- Chất liệu: Da bò thật</p> <p>Mẫu móc chìa khóa nằm trong bộ sưu tập MCK Light của Đỏ, gồm những thiết kế mô phỏng ánh sáng được vẽ theo kiểu cách điệu đầy ấn tượng. Các ánh sáng đó có thể là từ nguồn tự nhiên như mặt trăng (Moonlight) hay mặt trời (Sunlight), từ ngọn nến lung linh trong đêm, hoặc thậm chí là thứ gì đó trừu tượng hơn như “tình yêu”. Vì vậy, mỗi một thiết kế trong bộ sưu tập này đều có hàm ý riêng biệt và đầy ý nghĩa. Hãy nhanh chóng tìm cho mình một ánh sáng phù hợp nhất với bản ngã nhé.</p> a:4:{s:17:"rs_brand_producer";a:5:{i:0;s:63:"Thương hiệu Việt đầy tính nghệ thuật, sáng tạo";i:1;s:86:"Tiên phong trong việc tạo ra một dòng phụ kiện da thủ công độc đáo";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}s:14:"rs_ingredients";a:5:{i:0;s:15:"100% da thật ";i:1;s:75:"Phôi ốp đặt riêng chống sốc và bảo vệ điện thoại tốt";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}s:14:"rs_manufacture";a:5:{i:0;s:48:"Lựa chọn mẫu da thuộc để sử dụng ";i:1;s:42:"Thiết kế độc đáo theo chủ đề";i:2;s:17:"Vẽ thủ công ";i:3;s:0:"";i:4;s:0:"";}s:17:"rs_certifications";a:5:{i:0;s:0:"";i:1;s:0:"";i:2;s:0:"";i:3;s:0:"";i:4;s:0:"";}} <p>Bạn muốn móc khóa mang dấu ấn cá nhân của mình?</p> <p> </p> <p>- Móc khóa có thể được khắc tên riêng của bạn</p> <p> </p> <p>- Độ dài tên riêng để khắc nên từ </p> <p><strong style="color: #ff0000;">5-7 ký tự</strong></p> <p> </p> <p>- Vui lòng hãy ghi tên mà bạn muốn khắc trên móc chìa khóa vào ô "Lưu ý từ khách hàng"</p> <p> </p> <p><em>Lưu ý: Thời gian làm có thể kéo dài từ 7-10 ngày. Khách hàng có thể cân nhắc trước khi đặt</em></p> 0 230000.0000 149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,149M,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409 416M,416M,416M,418,418,418,420,420,420,421,421,421,423,423,423,425,425,425,426,426,426,444,444,444,453,453,453,460,460,460,467,467,467,491,491,491,492,492,492,496,496,496,514,514,514,515,515,515 63991 ĐỎ 3 glow-moc-chia-khoa-da-ve-tay-bst-mck-light-vi 99/149 D 4.93 15 2