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 (
    22245, 20836, 22413, 20328, 20327, 19648, 
    20527, 21925, 22368, 24723, 23624, 
    23625, 21058, 20439, 22576, 21287, 
    20334, 24704, 24781, 20450
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.03406

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": 20,
              "filtered": 100,
              "index_condition": "pf.feature_id in (22245,20836,22413,20328,20327,19648,20527,21925,22368,24723,23624,23625,21058,20439,22576,21287,20334,24704,24781,20450)"
            }
          }
        }
      },
      {
        "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
22576 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
19648 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20327 dropdown_labels 0 group_variation_catalog_item N Size giày Size giày 1
20328 dropdown_labels 0 group_variation_catalog_item N Size giày Size giày 1
20334 dropdown_labels 0 group_variation_catalog_item N Size giày Size giày 1
20439 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20450 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20527 dropdown_labels 0 group_variation_catalog_item N Chọn set Chọn set 1
20836 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
21287 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21925 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22245 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22368 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22413 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23624 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10207_31 - mẫu 1
23625 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10207_31 - màu 1
24704 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10743_06 - màu 1
24723 dropdown_labels 0 group_variation_catalog_item N Chọn hương nến 10528_08 1
24781 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10779_02 - màu 1