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 (
    24230, 21461, 23804, 22566, 20036, 23626, 
    20042, 21964, 20296, 22574, 20329, 
    20330, 22563, 24242, 22570, 23802, 
    23803, 24630, 24199, 20043
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.01787

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 (24230,21461,23804,22566,20036,23626,20042,21964,20296,22574,20329,20330,22563,24242,22570,23802,23803,24630,24199,20043)"
            }
          }
        }
      },
      {
        "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
22563 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
22566 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
22570 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
22574 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
20036 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20042 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20043 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20296 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20329 dropdown_labels 0 group_variation_catalog_item N Size giày Size giày 1
20330 dropdown_labels 0 group_variation_catalog_item N Size giày Size giày 1
21461 dropdown_labels 0 group_variation_catalog_item N Chọn size Chọn size 1
21964 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23626 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10207_32 - màu 1
23802 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10298_19 - màu 1
23803 dropdown_labels 0 group_variation_catalog_item N Chọn kích cỡ nệm 10298_19 - size 1
23804 dropdown_labels 0 group_variation_catalog_item N Chọn màu sắc 10298_15 - màu nap mat 1
24199 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10480_01 - option 1
24230 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10710_09 - màu 1
24242 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10480_02 - lon 1
24630 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10730_09 - option 1