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 (
    20472, 20471, 20470, 20469, 20473, 20468, 
    20466, 20467, 20462, 23620, 23621, 
    20474, 23622, 23623, 20465, 24865, 
    24866, 20464, 20463, 20458, 20461, 
    20459, 23618, 23619, 20457, 20456, 
    23624, 23625
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00271

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": 28,
              "filtered": 100,
              "index_condition": "pf.feature_id in (20472,20471,20470,20469,20473,20468,20466,20467,20462,23620,23621,20474,23622,23623,20465,24865,24866,20464,20463,20458,20461,20459,23618,23619,20457,20456,23624,23625)"
            }
          }
        }
      },
      {
        "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
20456 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20457 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20458 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20459 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20461 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20462 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20463 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20464 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20465 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20466 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20467 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20468 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20469 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20470 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20471 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20472 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20473 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20474 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23618 dropdown_labels 0 group_variation_catalog_item N Choose Figurine 10207_28 - mẫu 1
23619 dropdown_labels 0 group_variation_catalog_item N Choose color 10207_28 - màu 1
23620 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10207_29 - mẫu 1
23621 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10207_29 - màu 1
23622 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10207_30 - mẫu 1
23623 dropdown_labels 0 group_variation_catalog_item N Chọn màu mèo 10207_30 - màu 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
24865 dropdown_labels 0 group_variation_catalog_item N Chọn rồng 10207_33 - option 1
24866 dropdown_labels 1 group_variation_catalog_item N Chọn màu tượng 10207_33 - màu 1