Skip to main content

Small integers

Motivation

As of March 2025, Voedger does not support 2-byte and 1-byte integers. This limitation causes unnecessary storage and processing overhead, particularly for data types that don't require the full range of 4-byte integers.

Introduction

This document outlines the implementation of two smaller integer data types in Voedger: smallint (2 bytes) and tinyint (1 byte). Adding these types will optimize storage utilization and processing efficiency for appropriate use cases.

smallint

A 2-byte signed integer type with range from -32,768 to 32,767.

smallint is declared in ISO/IEC 9075 standard and is widely supported by popular SQL database systems:

tinyint

A 1-byte signed integer type with range from -128 to 127

While not declared in the ISO/IEC 9075 standard, tinyint is implemented by several major SQL database systems:

Functional design

Example of a view with smallint and tinyint columns:

VIEW MeasurementAggr (

-- Partion key

ID smallint,
Period smallint,
Cluster smallint,

-- Clustering key

Year smallint,
Month tinyint,
Day tinyint,
Hour tinyint,
Minute tinyint,
Second tinyint,

-- Value

Cnt smallint, -- Number of measurements
Sum double precision, -- Sum of measurements
Min double precision, -- Minimal measurement
Max double precision -- Maximum measurement

PRIMARY KEY ((ID, Period, Cluster), Year, Month, Day, Hour, Minute, Second)
)

Technical design

  • ~cmp.AppDef~covrd1✅: Support new data types
  • ~cmp.Parser~covrd2✅: Support new data types
  • ~cmp.istructs~covrd3✅: Add new members to IRowReader and IRowWriter interfaces
  • ~cmp.istructsmem~covrd4✅: Implement new members of IRowReader and IRowWriter interfaces

Test plan

  • ~it.SmallIntegers~covrd5

Addressed issues

Footnotes

Footnotes

  1. [~server.vsql.smallints/cmp.AppDef~impl] pkg/appdef/constraints/constraint.go:109:impl, pkg/appdef/constraints/constraint.go:171:impl, pkg/appdef/constraints/constraint.go:173:impl, pkg/appdef/consts.go:66:impl, pkg/appdef/consts.go:67:impl, pkg/appdef/examples/example_field_test.go:100:impl, pkg/appdef/interface_data.go:19:impl, pkg/appdef/interface_data.go:20:impl, pkg/appdef/internal/datas/data.go:106:impl, pkg/appdef/internal/datas/data.go:108:impl, pkg/appdef/internal/datas/data_test.go:320:impl, pkg/appdef/utils_data.go:28:impl, pkg/appdef/utils_data.go:80:impl, pkg/appdef/utils_data_test.go:27:impl, pkg/appdef/utils_data_test.go:116:impl, pkg/appdef/utils_data_test.go:119:impl, pkg/appdef/utils_data_test.go:150:impl, pkg/appdef/utils_data_test.go:233:impl, pkg/appdef/utils_data_test.go:242:impl, pkg/appdef/utils_type.go:433:impl, pkg/appdef/utils_type.go:543:impl

  2. [~server.vsql.smallints/cmp.Parser~impl] pkg/parser/utils.go:379:impl

  3. [~server.vsql.smallints/cmp.istructs~impl] pkg/istructs/types.go:51:impl, pkg/istructs/types.go:52:impl, pkg/istructs/types.go:77:impl, pkg/istructs/types.go:78:impl, pkg/istructs/utils.go:55:impl, pkg/istructs/utils.go:56:impl, pkg/istructs/utils.go:88:impl, pkg/istructs/utils.go:89:impl, pkg/istructs/utils_test.go:111:impl, pkg/istructs/utils_test.go:112:impl, pkg/istructs/utils_test.go:138:impl, pkg/istructs/utils_test.go:139:impl, pkg/istructsmem/tables-types.go:63:impl, pkg/istructsmem/tables-types.go:65:impl, pkg/istructsmem/tables-types.go:164:impl, pkg/istructsmem/tables-types.go:184:impl, pkg/istructsmem/tables-types.go:186:impl, pkg/istructsmem/types-dynobuf.go:36:impl, pkg/istructsmem/types-dynobuf.go:43:impl, pkg/istructsmem/viewrecords-dynobuf.go:113:impl, pkg/istructsmem/viewrecords-dynobuf.go:118:impl, pkg/istructsmem/viewrecords-types.go:334:impl, pkg/istructsmem/viewrecords-types.go:344:impl, pkg/istructsmem/viewrecords-types.go:518:impl, pkg/istructsmem/viewrecords-types.go:529:impl

  4. [~server.vsql.smallints/cmp.istructsmem~impl] pkg/istructsmem/internal/dynobuf/utils.go:27:impl, pkg/istructsmem/types.go:318:impl, pkg/istructsmem/types.go:530:impl, pkg/istructsmem/types.go:541:impl, pkg/istructsmem/types.go:592:impl, pkg/istructsmem/types.go:595:impl, pkg/istructsmem/types.go:599:impl, pkg/istructsmem/types.go:823:impl, pkg/istructsmem/types.go:830:impl, pkg/istructsmem/types.go:885:impl, pkg/istructsmem/types.go:887:impl, pkg/istructsmem/types.go:930:impl, pkg/istructsmem/types.go:932:impl

  5. [~server.vsql.smallints/it.SmallIntegers~impl] pkg/parser/impl_test.go:2975:impl