SELECT 
  SQL_CALC_FOUND_ROWS products.product_id, 
  IF(
    shared_descr.product_id IS NOT NULL, 
    shared_descr.product, descr1.product
  ) as product, 
  companies.company as company_name, 
  variation_group_products.group_id AS variation_group_id, 
  products.product_type, 
  products.parent_product_id, 
  1 as instock_marker, 
  IF(
    products.product_type = 'C', 
    (
      SELECT 
        MAX(amount) 
      FROM 
        cscart_products 
      WHERE 
        parent_product_id = products.product_id
    ) > 0, 
    IF(
      products.amount > 0, 
      1, 
      IF(products.tracking = 'O', 1, 0)
    )
  ) as instock_sorting 
FROM 
  cscart_products as products 
  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_ult_product_descriptions shared_descr ON shared_descr.product_id = products.product_id 
  AND shared_descr.company_id = 1 
  AND shared_descr.lang_code = 'en' 
  LEFT JOIN cscart_images_links as img_links ON img_links.object_id = products.product_id 
  AND img_links.object_type = 'product' 
  AND img_links.type = 'M' 
  INNER JOIN cscart_product_variation_group_products AS variation_group_products ON variation_group_products.product_id = products.product_id 
WHERE 
  1 
  AND companies.status IN ('A') 
  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 img_links.pair_id > 0 
  AND variation_group_products.group_id IN (952) 
GROUP BY 
  products.product_id 
ORDER BY 
  instock_sorting DESC, 
  product asc, 
  products.product_id ASC 
LIMIT 
  0, 100

Query time 0.00671

JSON explain

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "if(products.product_type = 'C',(subquery#2) > 0,if(products.amount > 0,1,if(products.tracking = 'O',1,0))) desc, if(shared_descr.product_id is not null,shared_descr.product,descr1.product), products.product_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "companies",
              "access_type": "system",
              "possible_keys": ["PRIMARY"],
              "rows": 1,
              "filtered": 100
            }
          },
          {
            "table": {
              "table_name": "variation_group_products",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "idx_group_id"],
              "key": "idx_group_id",
              "key_length": "3",
              "used_key_parts": ["group_id"],
              "ref": ["const"],
              "rows": 172,
              "filtered": 100,
              "attached_condition": "variation_group_products.group_id <=> 952"
            }
          },
          {
            "table": {
              "table_name": "products",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "status"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.variation_group_products.product_id"],
              "rows": 1,
              "filtered": 90.50141144,
              "attached_condition": "products.company_id = 1 and (products.usergroup_ids = '' or find_in_set(0,products.usergroup_ids) or find_in_set(1,products.usergroup_ids)) and products.`status` = 'A'"
            }
          },
          {
            "table": {
              "table_name": "shared_descr",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "product_id", "company_id"],
              "key": "PRIMARY",
              "key_length": "13",
              "used_key_parts": ["product_id", "lang_code", "company_id"],
              "ref": [
                "lillyshop_lillyshop.variation_group_products.product_id",
                "const",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "trigcond(shared_descr.lang_code = 'en')"
            }
          },
          {
            "table": {
              "table_name": "descr1",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "product_id"],
              "key": "PRIMARY",
              "key_length": "9",
              "used_key_parts": ["product_id", "lang_code"],
              "ref": [
                "lillyshop_lillyshop.variation_group_products.product_id",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "trigcond(descr1.lang_code = 'en')"
            }
          },
          {
            "table": {
              "table_name": "prices",
              "access_type": "ref",
              "possible_keys": [
                "usergroup",
                "product_id",
                "lower_limit",
                "usergroup_id"
              ],
              "key": "usergroup",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.variation_group_products.product_id"],
              "rows": 1,
              "filtered": 99.99145508,
              "attached_condition": "prices.lower_limit = 1 and prices.usergroup_id in (0,0,1)",
              "using_index": true
            }
          },
          {
            "table": {
              "table_name": "products_categories",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "pt"],
              "key": "pt",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["lillyshop_lillyshop.variation_group_products.product_id"],
              "rows": 1,
              "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": ["lillyshop_lillyshop.products_categories.category_id"],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "(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)"
            }
          },
          {
            "table": {
              "table_name": "img_links",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "object_id"],
              "key": "object_id",
              "key_length": "81",
              "used_key_parts": ["object_id", "object_type", "type"],
              "ref": [
                "lillyshop_lillyshop.variation_group_products.product_id",
                "const",
                "const"
              ],
              "rows": 1,
              "filtered": 100,
              "index_condition": "img_links.object_id = variation_group_products.product_id and img_links.object_type = 'product' and img_links.`type` = 'M'",
              "attached_condition": "img_links.pair_id > 0"
            }
          }
        ],
        "subqueries": [
          {
            "expression_cache": {
              "state": "uninitialized",
              "query_block": {
                "select_id": 2,
                "nested_loop": [
                  {
                    "table": {
                      "table_name": "cscart_products",
                      "access_type": "ALL",
                      "possible_keys": ["idx_parent_product_id"],
                      "rows": 11707,
                      "filtered": 100,
                      "attached_condition": "cscart_products.parent_product_id = products.product_id"
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

Result

product_id product company_name variation_group_id product_type parent_product_id instock_marker instock_sorting
9953 Gel polish Oxxi No. 164 bright red-orange neon, 10 ml LILLYSHOP 952 P 0 1 1
9942 Gel polish Oxxi No. 234 light lilac enamel, 10 ml LILLYSHOP 952 P 0 1 1
9676 Gel polish Oxxi No. 241 bright lemon-yellow neon, 10 ml LILLYSHOP 952 P 0 1 1
9932 Gel polish Oxxi No. 254 slightly greenish gray, 10 ml LILLYSHOP 952 P 0 1 1
9937 Oxxi gel polish No. 003, light peach, 10 ml LILLYSHOP 952 P 0 1 1
9573 Oxxi gel polish No. 004 pale red enamel, 10 ml LILLYSHOP 952 P 0 1 1
9574 Oxxi gel polish No. 006, crimson-red with shimmer, 10 ml LILLYSHOP 952 P 0 1 1
9575 Oxxi gel polish No. 007, light crimson, 10 ml LILLYSHOP 952 P 0 1 1
9576 Oxxi gel polish No. 008, red, 10 ml LILLYSHOP 952 P 0 1 1
9577 Oxxi gel polish No. 010, pale pink-coral enamel, 10 ml LILLYSHOP 952 P 0 1 1
9672 Oxxi gel polish No. 011, pink, 10 ml LILLYSHOP 952 P 0 1 1
9578 Oxxi gel polish No. 012, raspberry, 10 ml LILLYSHOP 952 P 0 1 1
9638 Oxxi gel polish No. 013, light pink, 10 ml LILLYSHOP 952 P 0 1 1
9643 Oxxi gel polish No. 015, deep pink, 10 ml LILLYSHOP 952 P 0 1 1
9671 Oxxi gel polish No. 017, deep raspberry, 10 ml LILLYSHOP 952 P 0 1 1
9581 Oxxi gel polish No. 019, bright pink with microglitter, 10 ml LILLYSHOP 952 P 0 1 1
9582 Oxxi gel polish No. 020, bright crimson, 10 ml LILLYSHOP 952 P 0 1 1
9584 Oxxi gel polish No. 022, pink, 10 ml LILLYSHOP 952 P 0 1 1
9585 Oxxi gel polish No. 023, light red with microglitter, 10 ml LILLYSHOP 952 P 0 1 1
8687 Oxxi gel polish No. 024, orange-red, 10 ml LILLYSHOP 952 P 0 1 1
9685 Oxxi gel polish No. 027, light brown-gray, 10 ml LILLYSHOP 952 P 0 1 1
9954 Oxxi gel polish No. 029, light purple-pink, 10 ml LILLYSHOP 952 P 0 1 1
9681 Oxxi gel polish No. 030, light gray, 10 ml LILLYSHOP 952 P 0 1 1
9682 Oxxi gel polish No. 031, pale yellow, 10 ml LILLYSHOP 952 P 0 1 1
9955 Oxxi gel polish No. 032, soft pink with micro-glitter, 10 ml LILLYSHOP 952 P 0 1 1
9683 Oxxi gel polish No. 033, pale pink, 10 ml LILLYSHOP 952 P 0 1 1
9686 Oxxi gel polish No. 035, pastel coral-pink, 10 ml LILLYSHOP 952 P 0 1 1
9956 Oxxi gel polish No. 036, blue-gray, 10 ml LILLYSHOP 952 P 0 1 1
9758 Oxxi gel polish No. 038, pastel beige-pink, 10 ml LILLYSHOP 952 P 0 1 1
9612 Oxxi gel polish No. 039, muted gray-blue, 10 ml LILLYSHOP 952 P 0 1 1
9730 Oxxi gel polish No. 041, light purple with microglitter, 10 ml LILLYSHOP 952 P 0 1 1
9616 Oxxi gel polish No. 043, dark lilac, 10 ml LILLYSHOP 952 P 0 1 1
8933 Oxxi gel polish No. 044, dark purple with micro-glitter, 10 ml LILLYSHOP 952 P 0 1 1
9732 Oxxi gel polish No. 047, dark lilac, 10 ml LILLYSHOP 952 P 0 1 1
9735 Oxxi gel polish No. 049, purple with pink sparkles, 10 ml LILLYSHOP 952 P 0 1 1
9587 Oxxi gel polish No. 051, purple, 10 ml LILLYSHOP 952 P 0 1 1
9589 Oxxi gel polish No. 053, dark purple with blue microglitter, 10 ml LILLYSHOP 952 P 0 1 1
9599 Oxxi gel polish No. 059, dark turquoise, 10 ml LILLYSHOP 952 P 0 1 1
8936 Oxxi gel polish No. 060, coffee with microgloss, 10 ml LILLYSHOP 952 P 0 1 1
9565 Oxxi gel polish No. 061, olive, 10 ml LILLYSHOP 952 P 0 1 1
9600 Oxxi gel polish No. 062, muted gray-blue, 10 ml LILLYSHOP 952 P 0 1 1
9604 Oxxi gel polish No. 063, very dark turquoise with microglitter, 10 ml LILLYSHOP 952 P 0 1 1
9606 Oxxi gel polish No. 064, dark gray-pink, 10 ml LILLYSHOP 952 P 0 1 1
9947 Oxxi gel polish No. 066, light beige, 10 ml LILLYSHOP 952 P 0 1 1
9621 Oxxi gel polish No. 067, pink-coffee, 10 ml LILLYSHOP 952 P 0 1 1
9610 Oxxi gel polish No. 069, pink cocoa, 10 ml LILLYSHOP 952 P 0 1 1
8939 Oxxi gel polish No. 070, pale pink-peach, 10 ml LILLYSHOP 952 P 0 1 1
9611 Oxxi gel polish No. 072, light peach, 10 ml LILLYSHOP 952 P 0 1 1
9664 Oxxi gel polish No. 073, pale pink enamel, 10 ml LILLYSHOP 952 P 0 1 1
9665 Oxxi gel polish No. 074, light beige, 10 ml LILLYSHOP 952 P 0 1 1
9748 Oxxi gel polish No. 075, pale coral, 10 ml LILLYSHOP 952 P 0 1 1
9564 Oxxi gel polish No. 076, brown, 10 ml LILLYSHOP 952 P 0 1 1
9750 Oxxi gel polish No. 078, dark brown with micro-glitter, 10 ml LILLYSHOP 952 P 0 1 1
9623 Oxxi gel polish No. 080, pale Marsala, 10 ml LILLYSHOP 952 P 0 1 1
9958 Oxxi gel polish No. 085, red-brown with microglitter, 10 ml LILLYSHOP 952 P 0 1 1
9960 Oxxi gel polish No. 092, dark red-brown, 10 ml LILLYSHOP 952 P 0 1 1
9666 Oxxi gel polish No. 093, yellow with subtle sparkles, 10 ml LILLYSHOP 952 P 0 1 1
9952 Oxxi gel polish No. 095, silver, 10 ml LILLYSHOP 952 P 0 1 1
9959 Oxxi gel polish No. 096, light beige with small sparkles, 10 ml LILLYSHOP 952 P 0 1 1
9949 Oxxi gel polish No. 102, light purple, 10 ml LILLYSHOP 952 P 0 1 1
9753 Oxxi gel polish No. 103, lilac enamel, 10 ml LILLYSHOP 952 P 0 1 1
9944 Oxxi gel polish No. 104, mint enamel, 10 ml LILLYSHOP 952 P 0 1 1
9754 Oxxi gel polish No. 105, light turquoise, 10 ml LILLYSHOP 952 P 0 1 1
9562 Oxxi gel polish No. 107, light blue, 10 ml LILLYSHOP 952 P 0 1 1
9756 Oxxi gel polish No. 108, bright pink, 10 ml LILLYSHOP 952 P 0 1 1
8983 Oxxi gel polish No. 109, pale red-coral, 10 ml LILLYSHOP 952 P 0 1 1
9673 Oxxi gel polish No. 110, light pink, 10 ml LILLYSHOP 952 P 0 1 1
9961 Oxxi gel polish No. 111, dark red, 10 ml LILLYSHOP 952 P 0 1 1
9957 Oxxi gel polish No. 112, bright red-yellow-hot, 10 ml LILLYSHOP 952 P 0 1 1
9757 Oxxi gel polish No. 115, silver with holographic glitter, 10 ml LILLYSHOP 952 P 0 1 1
9626 Oxxi gel polish No. 116 10 ml LILLYSHOP 952 P 0 1 1
9627 Oxxi gel polish No. 118 10 ml LILLYSHOP 952 P 0 1 1
9629 Oxxi gel polish No. 120 10 ml LILLYSHOP 952 P 0 1 1
9630 Oxxi gel polish No. 121 10 ml LILLYSHOP 952 P 0 1 1
9632 Oxxi gel polish No. 123 10 ml LILLYSHOP 952 P 0 1 1
9633 Oxxi gel polish No. 124 10 ml LILLYSHOP 952 P 0 1 1
9635 Oxxi gel polish No. 125 10 ml LILLYSHOP 952 P 0 1 1
9640 Oxxi gel polish No. 133 10 ml LILLYSHOP 952 P 0 1 1
9945 Oxxi gel polish No. 134 10 ml LILLYSHOP 952 P 0 1 1
9950 Oxxi gel polish No. 135 10 ml LILLYSHOP 952 P 0 1 1
9641 Oxxi gel polish No. 140 10 ml LILLYSHOP 952 P 0 1 1
8945 Oxxi gel polish No. 151 10 ml LILLYSHOP 952 P 0 1 1
9625 Oxxi gel polish No. 152 10 ml LILLYSHOP 952 P 0 1 1
9645 Oxxi gel polish No. 154 10 ml LILLYSHOP 952 P 0 1 1
9647 Oxxi gel polish No. 158 10 ml LILLYSHOP 952 P 0 1 1
9677 Oxxi gel polish No. 159 10 ml LILLYSHOP 952 P 0 1 1
9648 Oxxi gel polish No. 160 10 ml LILLYSHOP 952 P 0 1 1
9650 Oxxi gel polish No. 166 light turquoise, 10 ml LILLYSHOP 952 P 0 1 1
9921 Oxxi gel polish No. 171 10 ml LILLYSHOP 952 P 0 1 1
8941 Oxxi gel polish No. 173 10 ml LILLYSHOP 952 P 0 1 1
9922 Oxxi gel polish No. 182 10 ml LILLYSHOP 952 P 0 1 1
9923 Oxxi gel polish No. 183 10 ml LILLYSHOP 952 P 0 1 1
9925 Oxxi gel polish No. 185 10 ml LILLYSHOP 952 P 0 1 1
9924 Oxxi gel polish No. 187 10 ml LILLYSHOP 952 P 0 1 1
9745 Oxxi gel polish No. 188 10 ml LILLYSHOP 952 P 0 1 1
9651 Oxxi gel polish No. 191 pale yellow, 10 ml LILLYSHOP 952 P 0 1 1
9652 Oxxi gel polish No. 199 10 ml LILLYSHOP 952 P 0 1 1
9746 Oxxi gel polish No. 201 10 ml LILLYSHOP 952 P 0 1 1
9654 Oxxi gel polish No. 221 10 ml LILLYSHOP 952 P 0 1 1
9926 Oxxi gel polish No. 222 bright crimson-pink, 10 ml LILLYSHOP 952 P 0 1 1