SELECT 
  SQL_CALC_FOUND_ROWS products.product_id, 
  descr1.product as product, 
  companies.company as company_name, 
  products.product_type, 
  products.parent_product_id 
FROM 
  cscart_products as products 
  INNER JOIN cscart_product_features_values as c_var ON c_var.product_id = products.product_id 
  AND c_var.lang_code = 'en' 
  AND c_var.variant_id = 1667 
  LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id 
  AND descr1.lang_code = 'en' 
  LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id 
  AND prices.lower_limit = 1 
  LEFT JOIN cscart_companies AS companies ON companies.company_id = products.company_id 
  INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id 
  INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id 
  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') 
  AND cscart_categories.storefront_id IN (0, 1) 
  LEFT JOIN cscart_product_popularity as popularity ON popularity.product_id = products.product_id 
WHERE 
  1 
  AND companies.status IN ('A') 
  AND (
    products.amount > 0 
    OR products.tracking = 'D'
  ) 
  AND (
    products.usergroup_ids = '' 
    OR FIND_IN_SET(0, products.usergroup_ids) 
    OR FIND_IN_SET(1, products.usergroup_ids)
  ) 
  AND products.status IN ('A') 
  AND prices.usergroup_id IN (0, 0, 1) 
  AND products.parent_product_id = 0 
  AND products.product_type != 'D' 
GROUP BY 
  products.product_id 
ORDER BY 
  popularity.total desc, 
  products.product_id ASC 
LIMIT 
  0, 40

Query time 0.02526

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "399.47"
    },
    "ordering_operation": {
      "using_filesort": true,
      "grouping_operation": {
        "using_temporary_table": true,
        "using_filesort": false,
        "nested_loop": [
          {
            "table": {
              "table_name": "companies",
              "access_type": "ALL",
              "possible_keys": [
                "PRIMARY"
              ],
              "rows_examined_per_scan": 10,
              "rows_produced_per_join": 1,
              "filtered": "10.00",
              "cost_info": {
                "read_cost": "1.46",
                "eval_cost": "0.10",
                "prefix_cost": "1.56",
                "data_read_per_join": "6K"
              },
              "used_columns": [
                "company_id",
                "status",
                "company"
              ],
              "attached_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`companies`.`status` = 'A')"
            }
          },
          {
            "table": {
              "table_name": "c_var",
              "access_type": "ref",
              "possible_keys": [
                "variant_id",
                "lang_code",
                "product_id",
                "idx_product_feature_variant_id"
              ],
              "key": "variant_id",
              "used_key_parts": [
                "variant_id"
              ],
              "key_length": "3",
              "ref": [
                "const"
              ],
              "rows_examined_per_scan": 790,
              "rows_produced_per_join": 256,
              "filtered": "32.52",
              "cost_info": {
                "read_cost": "197.50",
                "eval_cost": "25.69",
                "prefix_cost": "278.06",
                "data_read_per_join": "198K"
              },
              "used_columns": [
                "product_id",
                "variant_id",
                "lang_code"
              ],
              "attached_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`c_var`.`lang_code` = 'en')"
            }
          },
          {
            "table": {
              "table_name": "products",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "status",
                "idx_parent_product_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.c_var.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 12,
              "filtered": "5.00",
              "cost_info": {
                "read_cost": "64.22",
                "eval_cost": "1.28",
                "prefix_cost": "367.97",
                "data_read_per_join": "56K"
              },
              "used_columns": [
                "product_id",
                "product_type",
                "status",
                "company_id",
                "amount",
                "usergroup_ids",
                "tracking",
                "parent_product_id"
              ],
              "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`products`.`company_id` = `softwarepirmam_hewadelivard_cscart_4`.`companies`.`company_id`) and (`softwarepirmam_hewadelivard_cscart_4`.`products`.`parent_product_id` = 0) and ((`softwarepirmam_hewadelivard_cscart_4`.`products`.`amount` > 0) or (`softwarepirmam_hewadelivard_cscart_4`.`products`.`tracking` = 'D')) and ((`softwarepirmam_hewadelivard_cscart_4`.`products`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`products`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`products`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`products`.`status` = 'A') and (`softwarepirmam_hewadelivard_cscart_4`.`products`.`product_type` <> 'D'))"
            }
          },
          {
            "table": {
              "table_name": "prices",
              "access_type": "ref",
              "possible_keys": [
                "usergroup",
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "key": "product_id",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.c_var.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 12,
              "filtered": "99.93",
              "cost_info": {
                "read_cost": "3.21",
                "eval_cost": "1.28",
                "prefix_cost": "372.46",
                "data_read_per_join": "308"
              },
              "used_columns": [
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`prices`.`lower_limit` = 1) and (`softwarepirmam_hewadelivard_cscart_4`.`prices`.`usergroup_id` in (0,0,1)))"
            }
          },
          {
            "table": {
              "table_name": "popularity",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "total"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.c_var.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 12,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "3.21",
                "eval_cost": "1.28",
                "prefix_cost": "376.96",
                "data_read_per_join": "410"
              },
              "used_columns": [
                "product_id",
                "total"
              ]
            }
          },
          {
            "table": {
              "table_name": "descr1",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "product_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id",
                "lang_code"
              ],
              "key_length": "9",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.c_var.product_id",
                "const"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 12,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "3.26",
                "eval_cost": "1.28",
                "prefix_cost": "381.50",
                "data_read_per_join": "58K"
              },
              "used_columns": [
                "product_id",
                "lang_code",
                "product"
              ]
            }
          },
          {
            "table": {
              "table_name": "products_categories",
              "access_type": "ref",
              "possible_keys": [
                "PRIMARY",
                "pt"
              ],
              "key": "pt",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.c_var.product_id"
              ],
              "rows_examined_per_scan": 2,
              "rows_produced_per_join": 25,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "6.42",
                "eval_cost": "2.57",
                "prefix_cost": "390.48",
                "data_read_per_join": "410"
              },
              "used_columns": [
                "product_id",
                "category_id"
              ]
            }
          },
          {
            "table": {
              "table_name": "cscart_categories",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "c_status",
                "p_category_id"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "category_id"
              ],
              "key_length": "3",
              "ref": [
                "softwarepirmam_hewadelivard_cscart_4.products_categories.category_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 1,
              "filtered": "5.00",
              "cost_info": {
                "read_cost": "6.42",
                "eval_cost": "0.13",
                "prefix_cost": "399.47",
                "data_read_per_join": "4K"
              },
              "used_columns": [
                "category_id",
                "storefront_id",
                "usergroup_ids",
                "status"
              ],
              "attached_condition": "(((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)))"
            }
          }
        ]
      }
    }
  }
}

Result

product_id product company_name product_type parent_product_id
1274 Samsung Galaxy Tab A9+ Delivard Store P 0
1406 Samsung Galaxy S24 FE Delivard Store P 0
1266 Samsung Galaxy S24 Ultra Delivard Store P 0
1428 Samsung Galaxy A55 5G Delivard Store P 0
1263 Samsung Galaxy S24 Delivard Store P 0
1256 Samsung Galaxy A06 Delivard Store P 0
1319 Samsung Galaxy A56 5G Delivard Store P 0
1273 Samsung Galaxy Z Fold 6 Delivard Store P 0
4526 Samsung Galaxy S25 Ultra Delivard Store P 0
1532 Samsung QLED 4K Q60D Tizen OS Smart TV 65" Delivard Store P 0
4796 Galaxy Tab S10 Plus Delivard Store P 0
4562 Samsung Odyssey OLED G9 49" 1440p HDR 240 Hz Curved Ultrawide Gaming Monitor Delivard Store P 0
8499 Samsung QLED 4K Q60D Tizen OS Smart TV 85" Delivard Store P 0
8502 Samsung QLED 4K Q60D Tizen OS Smart TV 75" Delivard Store P 0
8501 Samsung QLED 4K Q60D Tizen OS Smart TV 55" Delivard Store P 0
4798 Samsung Tab S10 Ultra Delivard Store P 0
1284 Samsung Galaxy Watch6 Classic Delivard Store P 0
1528 Samsung QLED Q70D Series 4K Smart TV 65" [2024] Delivard Store P 0
4767 Samsung Galaxy A26 Delivard Store P 0
1542 Galaxy Buds 3 Delivard Store P 0
1517 Samsung OLED S90D 4K Tizen OS Smart TV 55" [2024] Delivard Store P 0
4744 Samsung Galaxy A36 5G Delivard Store P 0
8498 Samsung OLED S90D 4K Tizen OS Smart TV 65" [2024] Delivard Store P 0
8497 Samsung OLED S90D 4K Tizen OS Smart TV 77" [2024] Delivard Store P 0
4571 Samsung 27" Odyssey G7 (G70D) 4K UHD IPS 144Hz 1ms(GtG) Smart Gaming Monitor Delivard Store P 0
4812 Samsung Galaxy Watch 7 Delivard Store P 0
1540 Samsung Galaxy Buds FE Delivard Store P 0
1544 Samsung Galaxy Buds3 Pro Delivard Store P 0
1538 Samsung Crystal UHD DU8100 4K Tizen OS Smart TV 65" [2024] Delivard Store P 0
8503 Samsung QLED Q70D Series 4K Smart TV 85" [2024] Delivard Store P 0
8505 Samsung QLED Q70D Series 4K Smart TV 75" [2024] Delivard Store P 0
8496 Samsung Crystal UHD DU8100 4K Tizen OS Smart TV 55" [2024] Delivard Store P 0
4570 SAMSUNG 34 Odyssey QD-OLED G8 Curved Gaming Monitor Delivard Store P 0
4565 Samsung Essential S3 S30GD 24" FHD IPS Monitor – 100Hz, 5ms GTG, 250 nits, 178° Viewing Angle, VESA Mount, HDMI Input Delivard Store P 0
4567 Samsung Odyssey G50D 32 1440p HDR 180 Hz Gaming Monitor Delivard Store P 0
4568 Samsung Odyssey G7 G70D 32" 4K UHD IPS Gaming Monitor – 144Hz, 1ms GTG, HDR400, G-Sync Compatible, Gaming Hub, VESA Mount Delivard Store P 0
10136 Samsung S85F OLED 4K Smart TV Delivard Store P 0
10137 Samsung S85F OLED 4K Smart TV Delivard Store P 0
4569 Samsung ViewFinity S7 27 UHD IPS Monitor – 4K (3840×2160), HDR10, 350 nits, 5ms, 1.07B Colors, HDMI & DP, VESA Mount Delivard Store P 0
5774 Samsung Single Door Refrigerator with Frost-Free Technology Delivard Store P 0