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 (
    19651, 19723, 22334, 21291, 22573, 24099, 
    19650, 22245, 22419, 22831, 22333, 
    22551, 22413, 20977, 22553, 22826, 
    21115, 21034, 21147
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00310

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 (19651,19723,22334,21291,22573,24099,19650,22245,22419,22831,22333,22551,22413,20977,22553,22826,21115,21034,21147)"
            }
          }
        }
      },
      {
        "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
22573 dropdown_labels 0 group_catalog_item N Lựa chọn Lựa chọn 0
19650 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
19651 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
19723 dropdown_labels 0 group_variation_catalog_item N Chọn hương nến Chọn hương nến 1
20977 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21034 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21115 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21147 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21291 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22245 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22333 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22334 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22413 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22419 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22551 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22553 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22826 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22831 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
24099 dropdown_labels 0 group_variation_catalog_item N Chọn hoạ tiết 10418_34 - hoạ tiết 1