This disclosure provides a data storage method and apparatus. The method includes: acquiring target data to be stored; reading a
bitmap structure from a
database based on a target identifier in the target data; and determining the mode of the
bitmap structure. When the
bitmap structure is determined to be in a variable-length mode, writing a target time from the target data into a newly added time unit in the data portion of the bitmap structure, wherein the data portion of the variable-length bitmap structure contains at least one time unit. When the bitmap structure is determined to be in a fixed-length mode, setting corresponding
data bits in the data portion of the bitmap
structure based on the target time in the target data, wherein the storage location of each data bit in the data portion of the fixed-length bitmap structure corresponds to a time point. This method can reduce the space occupied by data storage, thereby reducing storage costs, and improve the efficiency of
data retrieval, thereby reducing query latency.