Preventing excessive amounts of database records

I have a sensor sending data to HA using MQTT. Does every single event that is sent get recorded, or is it only state changes? For example if the sensor sends “Door Open” 100 times then “Door Closed” once does that create 101 records or 2?

The reason I’m asking is because I have a sensor that sends updates twice a second. If I create more then that’s a lot of extra data being sent. The alternative would be to re-write the firmware to put more logic into the sensor that will prevent so many updates from being sent.

Yes typically the sensor should only send his state change to avoid extra trafic, database entry, electricity consumption, … (an esp8266 for example will use much more current when sending data over wifi).