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 (
    23184, 24842, 21339, 20474, 23527, 24551, 
    24569, 20545, 24867, 24606, 22626, 
    23526, 23528, 25064, 21596, 24744
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00260

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": 16,
              "filtered": 100,
              "index_condition": "pf.feature_id in (23184,24842,21339,20474,23527,24551,24569,20545,24867,24606,22626,23526,23528,25064,21596,24744)"
            }
          }
        }
      },
      {
        "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
22626 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
20474 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20545 dropdown_labels 0 group_variation_catalog_item N Chọn loại nến thơm Chọn loại nến thơm 1
21339 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21596 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23184 dropdown_labels 0 group_variation_catalog_item N Chọn loại 10291_06 - màu 1
23526 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_02 - option 1
23527 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_03 - set 1
23528 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_05 - set 1
24551 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10294_22 - color 1
24569 dropdown_labels 0 group_variation_catalog_item N Chọn kích thước 10294_24 - size 1
24606 dropdown_labels 0 group_variation_catalog_item N Chọn mùi nến 10212_02 - mùi 1
24744 dropdown_labels 0 group_variation_catalog_item N Chọn size nhẫn 10018_104 - size nhẫn 1
24842 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10291_21 - option 1
24867 dropdown_labels 0 group_variation_catalog_item N Chọn mẫu 10294_27 - mẫu 1
25064 dropdown_labels 0 group_variation_catalog_item Y Chọn size Chọn size 1