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 (
    23744, 21383, 22337, 19628, 23357, 24063, 
    21666, 22348, 21024, 21225, 19804, 
    21229, 20463, 24545, 22517, 19999, 
    20107, 20458, 21013
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00583

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": 19,
              "filtered": 100,
              "index_condition": "pf.feature_id in (23744,21383,22337,19628,23357,24063,21666,22348,21024,21225,19804,21229,20463,24545,22517,19999,20107,20458,21013)"
            }
          }
        }
      },
      {
        "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
19628 dropdown_labels 0 group_variation_catalog_item N Lựa chọn loại tinh dầu Lựa chọn loại tinh dầu 1
19804 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
19999 dropdown_labels 0 group_variation_catalog_item N Chọn mức xay Chọn mức xay 1
20107 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
20463 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21013 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21024 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21225 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21229 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21383 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21666 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22337 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22348 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22517 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23357 dropdown_labels 0 group_variation_catalog_item N Chọn hộp trà 10520_02 - trà 1
23744 dropdown_labels 0 group_variation_catalog_item N Chọn size 10044_01 - Size 1
24063 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10048_27 - Mẫu 1
24545 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10471_16 - option 1