SELECT 
  w.warehouse_id, 
  p.product_id, 
  COALESCE(wp.amount, 0) AS amount 
FROM 
  cscart_erp_warehouse w 
  LEFT JOIN (
    SELECT 
      DISTINCT product_id 
    FROM 
      cscart_erp_warehouse_products 
    WHERE 
      product_id = 166
  ) p ON 1 = 1 
  LEFT JOIN cscart_erp_warehouse_products wp ON w.warehouse_id = wp.warehouse_id 
  AND wp.product_id = p.product_id 
WHERE 
  w.warehouse_id IN ('1', '2', '3')

Query time 0.00154

JSON explain

{
  "query_block": {
    "select_id": 1,
    "table": {
      "table_name": "w",
      "access_type": "range",
      "possible_keys": ["PRIMARY"],
      "key": "PRIMARY",
      "key_length": "4",
      "used_key_parts": ["warehouse_id"],
      "rows": 3,
      "filtered": 100,
      "attached_condition": "w.warehouse_id in ('1','2','3')",
      "using_index": true
    },
    "block-nl-join": {
      "table": {
        "table_name": "<derived2>",
        "access_type": "ALL",
        "rows": 1959,
        "filtered": 100
      },
      "buffer_type": "flat",
      "buffer_size": "130",
      "join_type": "BNL",
      "attached_condition": "trigcond(trigcond(1 = 1)) and trigcond(1 = 1) and trigcond(1 = 1)",
      "materialized": {
        "query_block": {
          "select_id": 2,
          "table": {
            "table_name": "cscart_erp_warehouse_products",
            "access_type": "index",
            "key": "PRIMARY",
            "key_length": "8",
            "used_key_parts": ["warehouse_id", "product_id"],
            "rows": 1959,
            "filtered": 100,
            "attached_condition": "cscart_erp_warehouse_products.product_id = 166",
            "using_index": true
          }
        }
      }
    },
    "table": {
      "table_name": "wp",
      "access_type": "eq_ref",
      "possible_keys": ["PRIMARY"],
      "key": "PRIMARY",
      "key_length": "8",
      "used_key_parts": ["warehouse_id", "product_id"],
      "ref": ["bacpvdev_db.w.warehouse_id", "p.product_id"],
      "rows": 1,
      "filtered": 100,
      "attached_condition": "trigcond(trigcond(p.product_id is not null))"
    }
  }
}

Result

warehouse_id product_id amount
1 166 0.000
2 166 0.000
3 166 0.000