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 (
    23533, 23530, 24231, 19649, 23490, 21265, 
    23755, 24224, 22572, 21918, 22573, 
    21267, 23757, 19648, 22368, 22576, 
    22561
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00205

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": 17,
              "filtered": 100,
              "index_condition": "pf.feature_id in (23533,23530,24231,19649,23490,21265,23755,24224,22572,21918,22573,21267,23757,19648,22368,22576,22561)"
            }
          }
        }
      },
      {
        "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
22561 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
22572 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
22573 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
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
19649 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21265 dropdown_labels 0 group_variation_catalog_item N Chọn màu Chọn màu 1
21267 dropdown_labels 0 group_variation_catalog_item N Chọn màu Chọn màu 1
21918 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
23490 dropdown_labels 0 group_variation_catalog_item N Chọn size 10649_01 - size 1
23530 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_08 - set 1
23533 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_12 - set 1
23755 dropdown_labels 0 group_variation_catalog_item N Kích cỡ nệm Kích cỡ nệm 1
23757 dropdown_labels 0 group_variation_catalog_item N Kích cỡ nệm Kích cỡ nệm 1
24224 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10710_03 - màu 1
24231 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10710_10 - màu 1