Query Optimization for Wireless Sensor Network Databases in the MadWise system