![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Serialise / parse for the inversion-free tractability certificate. More...
#include "postgres.h"#include "lib/stringinfo.h"#include "utils/palloc.h"#include "safe_query_cert.h"#include <stdlib.h>#include <string.h>
Go to the source code of this file.
Macros | |
| #define | READ_INT(dst) |
Functions | |
| char * | safe_cert_serialise (const SafeCert *cert) |
Serialise a SafeCert recipe to a compact, C-prefixed string (palloc'd in the current memory context). | |
| SafeCert * | safe_cert_parse (const char *str) |
Parse a C-prefixed recipe string (as produced by safe_cert_serialise and read back from an annotation gate's extra) into a palloc'd SafeCert. | |
| char * | safe_cert_key_serialise (const char *root, size_t root_len, const char *sec, size_t sec_len, int factor) |
Serialise a per-input order key to a compact K-prefixed string (palloc'd). | |
| bool | safe_cert_key_parse (const char *str, SafeCertKey *out) |
Parse a K-prefixed order-key string into out. | |
Serialise / parse for the inversion-free tractability certificate.
The recipe travels from the planner (which builds it in safe_query.c) to the evaluator (probability_evaluate.cpp) as the extra string of the annotation gate wrapping the provenance root. The wire format is a compact, space-separated list of integers, prefixed by SAFE_CERT_EXTRA_PREFIX_RECIPE ('C') so a consumer can tell a recipe apart from a per-input order key ('K'):
C kind nclasses root_class natoms maxarity <class_topo_order[0..nclasses-1]> <atom_relation_rank[0..natoms-1]> <atom_col_class[0..natoms*maxarity-1]>
A per-input order key uses the sibling SAFE_CERT_EXTRA_PREFIX_KEY ('K') form "K<factor> <root_len>:<root><sec_len>:<sec>", length-prefixed so the class values may be arbitrary text (see safe_cert_key_serialise).
All functions are pure (no SPI / no catalog access) so the parsers are safe to call from the C++ evaluation side.
Definition in file safe_query_cert.c.
| #define READ_INT | ( | dst | ) |
| bool safe_cert_key_parse | ( | const char * | str, |
| SafeCertKey * | out ) |
Parse a K-prefixed order-key string into out.
On success out->root / out->sec point into str (valid for its lifetime). Returns false if str is NULL, not K-prefixed, or malformed (out untouched).
Definition at line 124 of file safe_query_cert.c.

| char * safe_cert_key_serialise | ( | const char * | root, |
| size_t | root_len, | ||
| const char * | sec, | ||
| size_t | sec_len, | ||
| int | factor ) |
Serialise a per-input order key to a compact K-prefixed string (palloc'd).
Wire form: "K<factor> <root_len>:<root><sec_len>:<sec>" – the byte-length prefixes keep arbitrary value text unambiguous. Inverse of safe_cert_key_parse. (The planner builds the equivalent string per row via inversion_free_key; this C form is for the evaluator and tests.)
Definition at line 111 of file safe_query_cert.c.
| SafeCert * safe_cert_parse | ( | const char * | str | ) |
Parse a C-prefixed recipe string (as produced by safe_cert_serialise and read back from an annotation gate's extra) into a palloc'd SafeCert.
Returns NULL if str is NULL, not C-prefixed, or malformed.
Definition at line 55 of file safe_query_cert.c.

| char * safe_cert_serialise | ( | const SafeCert * | cert | ) |
Serialise a SafeCert recipe to a compact, C-prefixed string (palloc'd in the current memory context).
Inverse of safe_cert_parse.
Definition at line 32 of file safe_query_cert.c.
