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 (
    19747, 19746, 23184, 24842, 21339, 21346, 
    24913, 24568, 24569, 24552, 24551, 
    21326, 24566, 24567, 23527, 23531, 
    23533, 21157, 23530, 23529
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.01930

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 (19747,19746,23184,24842,21339,21346,24913,24568,24569,24552,24551,21326,24566,24567,23527,23531,23533,21157,23530,23529)"
            }
          }
        }
      },
      {
        "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
19746 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
19747 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21157 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21326 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21339 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21346 dropdown_labels 0 group_variation_catalog_item N Lựa chọn màu vải Lựa chọn màu vải 1
23184 dropdown_labels 0 group_variation_catalog_item N Chọn loại 10291_06 - màu 1
23527 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_03 - set 1
23529 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_07 - set 1
23530 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_08 - set 1
23531 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_10 - set 1
23533 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10506_12 - set 1
24551 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10294_22 - color 1
24566 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10294_23 - màu 1
24568 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10294_24 - màu 1
24569 dropdown_labels 0 group_variation_catalog_item N Chọn kích thước 10294_24 - size 1
24842 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10291_21 - option 1
24913 dropdown_labels 0 group_variation_catalog_item N Tùy chọn Tùy chọn 1
24552 dropdown_labels 2 group_variation_catalog_item N Chọn kích thước 10294_22 - size 1
24567 dropdown_labels 2 group_variation_catalog_item N Chọn kích thước 10294_23 - size 1