SELECT 
  pf.feature_id, 
  pf.feature_style, 
  pf.position, 
  pf.purpose, 
  pf.display_on_catalog, 
  pfd.description, 
  pfd.internal_name, 
  pfd.prefix, 
  pfd.suffix, 
  (
    CASE WHEN pf.purpose = 'group_catalog_item' THEN 0 ELSE 1 END
  ) AS purpose_position 
FROM 
  cscart_product_features AS pf 
  INNER JOIN cscart_product_features_descriptions AS pfd ON pf.feature_id = pfd.feature_id 
  AND pfd.lang_code = 'vi' 
WHERE 
  pf.feature_id IN (
    21076, 24723, 24742, 22459, 21058, 21711, 
    24952, 20941, 19781, 20102, 20380, 
    24214, 23800, 21078, 20319, 25185, 
    24222, 24754
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.01061

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "read_sorted_file": {
          "filesort": {
            "sort_key": "case when pf.purpose = 'group_catalog_item' then 0 else 1 end, pf.position, pf.feature_id",
            "table": {
              "table_name": "pf",
              "access_type": "range",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["feature_id"],
              "rows": 18,
              "filtered": 100,
              "index_condition": "pf.feature_id in (21076,24723,24742,22459,21058,21711,24952,20941,19781,20102,20380,24214,23800,21078,20319,25185,24222,24754)"
            }
          }
        }
      },
      {
        "table": {
          "table_name": "pfd",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "9",
          "used_key_parts": ["feature_id", "lang_code"],
          "ref": ["dev_db.pf.feature_id", "const"],
          "rows": 1,
          "filtered": 100,
          "index_condition": "pfd.lang_code = 'vi'"
        }
      }
    ]
  }
}

Result

feature_id feature_style position purpose display_on_catalog description internal_name prefix suffix purpose_position
19781 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20102 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20319 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20380 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20941 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21058 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21076 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21078 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21711 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22459 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23800 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10298_17 - màu 1
24214 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10328_01 - gram 1
24222 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10710_01 - màu 1
24723 dropdown_labels 0 group_variation_catalog_item N Chọn hương nến 10528_08 1
24742 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10471_21 - màu 1
24754 dropdown_labels 0 group_variation_catalog_item N Chọn màu ms kén - màu 1
24952 dropdown_labels 0 group_variation_catalog_item N Tùy chọn Tùy chọn 1
25185 dropdown 0 group_variation_catalog_item N Lựa chọn 10481_option 1