Skip to content

Move pc_(point|patch)_(de)serialize into libpc.a#381

Open
estebanzimanyi wants to merge 1 commit intopgpointcloud:cmakefrom
estebanzimanyi:feat/libpc-serialize-expose
Open

Move pc_(point|patch)_(de)serialize into libpc.a#381
estebanzimanyi wants to merge 1 commit intopgpointcloud:cmakefrom
estebanzimanyi:feat/libpc-serialize-expose

Conversation

@estebanzimanyi
Copy link
Copy Markdown

Summary

The four functions pc_point_serialize, pc_point_deserialize,
pc_patch_serialize, and pc_patch_deserialize — together with
pc_patch_serialized_size, pc_patch_serialize_to_uncompressed, and
pc_patch_stats_deserialize — currently live in pgsql/pc_pgsql.c and
are compiled only into the PostgreSQL extension shared object. They are
therefore unreachable from libpc.a and from any non-PostgreSQL consumer
that links the static library.

Motivation

MobilityDB is adding
tpcpoint / tpcpatch temporal types (PR #818). Per-point filtering
operations (atTpcboxFine, eIntersects) need to decompose serialized
patches in C — roughly 10× faster than routing every patch through
PC_Explode in SQL. MEOS (the standalone C library at the core of
MobilityDB) links libpc.a but cannot reach the serialize/deserialize
functions today.

This is the upstream change that closes that gap. See also
MobilityDB discussion #869
for the community RFC.

Changes

File Change
lib/pc_serialize.c New file — moved implementations
lib/pc_api.h SERIALIZED_POINT/SERIALIZED_PATCH structs promoted here; new declarations added
lib/CMakeLists.txt pc_serialize.c added to PC_SOURCES
pgsql/pc_pgsql.h Duplicate struct/decl block removed (now in pc_api.h)
pgsql/pc_pgsql.c Implementations removed (now in lib/pc_serialize.c)

Minimal porting changes for PG-free compilation

To compile cleanly in libpc.a without PostgreSQL headers:

  • pallocpcalloc in pc_point_serialize (the patch helpers already used pcalloc)
  • elog(ERROR, ...)pcerror(...) in pc_point_deserialize
  • #ifndef SET_VARSIZE / VARSIZE fallbacks added in pc_serialize.c that are bit-for-bit compatible with PostgreSQL's 4-byte non-toasted varlena encoding

No breaking changes

  • On-disk format: unchanged
  • SQL surface: unchanged
  • PG extension build: unchanged (the symbols remain available, now from libpc.a)
  • libpc.a: additive only

Testing

The cmake branch build (libpc-static target) compiles cleanly with no new warnings.
The existing PG extension test suite (pgsql/expected/pointcloud.out) continues to cover all moved code paths.

The four functions pc_point_serialize, pc_point_deserialize,
pc_patch_serialize, and pc_patch_deserialize — together with
pc_patch_serialized_size, pc_patch_serialize_to_uncompressed, and
pc_patch_stats_deserialize — previously lived in pgsql/pc_pgsql.c and
were only reachable through the PostgreSQL extension shared object.

This commit moves them to a new lib/pc_serialize.c, which is compiled
into libpc.a.  The SERIALIZED_POINT and SERIALIZED_PATCH struct
definitions are promoted from pgsql/pc_pgsql.h to lib/pc_api.h so that
non-PostgreSQL consumers can use the types without including PG headers.

Changes:
  - lib/pc_serialize.c    new file with the moved implementations
  - lib/pc_api.h          SERIALIZED_POINT/PATCH structs + new declarations
  - lib/CMakeLists.txt    add pc_serialize.c to PC_SOURCES
  - pgsql/pc_pgsql.h      remove duplicated structs/decls (now in pc_api.h)
  - pgsql/pc_pgsql.c      remove implementations (now in lib/pc_serialize.c)

Two minimal porting changes are made to work without PG headers:
  - palloc → pcalloc in pc_point_serialize
  - elog(ERROR,...) → pcerror(...) in pc_point_deserialize
  - #ifndef SET_VARSIZE / VARSIZE fallbacks that are bit-compatible
    with PostgreSQL's non-toasted varlena encoding

No on-disk format changes.  No SQL surface changes.  libpc.a grows by
~550 lines of C that were already exercised by the PG extension tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant