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 (
    20607, 20609, 20598, 23469, 23470, 19939, 
    21672, 21659, 21670, 23449, 23313, 
    23314, 20645, 20574, 23626, 23325, 
    21657
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00267

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 (20607,20609,20598,23469,23470,19939,21672,21659,21670,23449,23313,23314,20645,20574,23626,23325,21657)"
            }
          }
        }
      },
      {
        "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
19939 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20574 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20598 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20607 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20609 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20645 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21657 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21659 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21670 dropdown_labels 0 group_variation_catalog_item N Chọn màu Chọn màu 1
21672 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23313 dropdown_labels 0 group_variation_catalog_item N Chọn cỡ bình 10579_06 - size 1
23314 dropdown_labels 0 group_variation_catalog_item N Chọn kiểu bình 10579_06 - kiểu bình 1
23325 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10579_17 - màu 1
23449 dropdown_labels 0 group_variation_catalog_item N Kích thước Kích thước 1
23469 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10207_27 - mẫu 1
23470 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10207_27 - màu 1
23626 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10207_32 - màu 1