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 (
    20251, 22929, 21060, 20301, 21152, 20903, 
    20033, 24759, 23836, 20321, 21070, 
    21450, 23270, 20037, 21062, 23584, 
    24940, 23702, 24934, 20255
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00199

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 (20251,22929,21060,20301,21152,20903,20033,24759,23836,20321,21070,21450,23270,20037,21062,23584,24940,23702,24934,20255)"
            }
          }
        }
      },
      {
        "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
20033 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20037 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20251 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm Lựa chọn mẫu cánh buồm 1
20255 dropdown_labels 0 group_variation_catalog_item N Lựa chọn mẫu cánh buồm: Lựa chọn mẫu cánh buồm: 1
20301 dropdown_labels 0 group_variation_catalog_item N Chọn chủ đề lịch Chọn chủ đề lịch 1
20321 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20903 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21060 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21062 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21070 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21152 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21450 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
22929 dropdown_labels 0 group_variation_catalog_item N Chọn màu hoa: 10561_01 - Choose color 1
23270 dropdown_labels 0 group_variation_catalog_item N Chọn mùi nến 10293_46 - mùi nến 1
23584 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10638_01 - gram 1
23702 dropdown_labels 0 group_variation_catalog_item N Chọn thể tích tinh dầu 10628_01 - thể tích 1
23836 dropdown_labels 0 group_variation_catalog_item N Chọn tượng mèo 10134_08 - mèo 1
24759 dropdown_labels 0 group_variation_catalog_item N Chọn loại nến 10287_ Chọn kích thước nến 1
24934 dropdown_labels 0 group_variation_catalog_item N Tùy chọn Tùy chọn 1
24940 dropdown_labels 0 group_variation_catalog_item N Tùy chọn Tùy chọn 1