SELECT 
  c.parent_id, 
  sm.search_phrases, 
  c.category_id 
FROM 
  ushop_categories AS c 
  LEFT JOIN ushop_ab__search_motivation AS sm ON sm.category_id = c.category_id 
  AND sm.lang_code = 'es' 
WHERE 
  c.id_path LIKE "%323%" 
  AND (
    sm.search_phrases != "NULL" 
    OR c.level = (
      SELECT 
        level 
      FROM 
        ushop_categories 
      WHERE 
        category_id = 323
    )
  ) 
  AND c.company_id = 0 
  AND c.status = "A"

Query time 0.00389

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "53.41"
    },
    "nested_loop": [
      {
        "table": {
          "table_name": "c",
          "access_type": "ALL",
          "rows_examined_per_scan": 481,
          "rows_produced_per_join": 1,
          "filtered": "0.21",
          "cost_info": {
            "read_cost": "52.96",
            "eval_cost": "0.10",
            "prefix_cost": "53.06",
            "data_read_per_join": "3K"
          },
          "used_columns": [
            "category_id",
            "parent_id",
            "id_path",
            "level",
            "company_id",
            "status"
          ],
          "attached_condition": "((`marketplace`.`c`.`company_id` = 0) and (`marketplace`.`c`.`id_path` like '%323%') and (`marketplace`.`c`.`status` = 'A'))"
        }
      },
      {
        "table": {
          "table_name": "sm",
          "access_type": "ref",
          "possible_keys": [
            "PRIMARY"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "category_id"
          ],
          "key_length": "3",
          "ref": [
            "marketplace.c.category_id"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "index_condition": "<if>(is_not_null_compl(sm), (`marketplace`.`sm`.`lang_code` = 'es'), true)",
          "cost_info": {
            "read_cost": "0.25",
            "eval_cost": "0.10",
            "prefix_cost": "53.41",
            "data_read_per_join": "32"
          },
          "used_columns": [
            "category_id",
            "lang_code",
            "search_phrases"
          ],
          "attached_condition": "<if>(found_match(sm), ((`marketplace`.`sm`.`search_phrases` <> 'NULL') or (`marketplace`.`c`.`level` = (/* select#2 */ select '1' from `marketplace`.`ushop_categories` where true))), true)",
          "attached_subqueries": [
            {
              "dependent": false,
              "cacheable": true,
              "query_block": {
                "select_id": 2,
                "cost_info": {
                  "query_cost": "1.00"
                },
                "table": {
                  "table_name": "ushop_categories",
                  "access_type": "const",
                  "possible_keys": [
                    "PRIMARY",
                    "p_category_id"
                  ],
                  "key": "PRIMARY",
                  "used_key_parts": [
                    "category_id"
                  ],
                  "key_length": "3",
                  "ref": [
                    "const"
                  ],
                  "rows_examined_per_scan": 1,
                  "rows_produced_per_join": 1,
                  "filtered": "100.00",
                  "cost_info": {
                    "read_cost": "0.00",
                    "eval_cost": "0.10",
                    "prefix_cost": "0.00",
                    "data_read_per_join": "3K"
                  },
                  "used_columns": [
                    "category_id",
                    "level"
                  ]
                }
              }
            }
          ]
        }
      }
    ]
  }
}

Result

parent_id search_phrases category_id
323 362
323 368
323 694
323 712
323 713
323 714
323 715
323 716
323 717
323 718
323 719
323 720
323 721
323 722
323 723
323 724
323 725
323 726
323 727
323 728
323 729
323 730
323 731
323 732
323 733
323 734
323 735
323 736
323 737
323 738
323 747
323 748
323 749
323 750
323 751
323 752
323 753
323 754
323 755
323 756
0 323