summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-09-30 00:51:54 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-09-30 00:51:54 +0100
commitedfaf671d016f675a3a3b87d58d615a92e84148b (patch)
treeca0175cac539709a33b6c81bda3611ed1b87fc4d
parent3e99d080b2a3a9b6eae85ae9e3224534744ad7b9 (diff)
downloadwebstat-edfaf671d016f675a3a3b87d58d615a92e84148b.tar.bz2
webstat-edfaf671d016f675a3a3b87d58d615a92e84148b.tar.xz
webstat-edfaf671d016f675a3a3b87d58d615a92e84148b.zip
Switch to PostgreSQL's oid type for entity ids
oid is an "unsigned 4 byte integer", which matches our crc32 approach perfectly, and is half the storage cost of bigint.
-rw-r--r--src/schema.sql14
-rw-r--r--test/test-ingest.cpp6
2 files changed, 10 insertions, 10 deletions
diff --git a/src/schema.sql b/src/schema.sql
index 4f3b205..602b70e 100644
--- a/src/schema.sql
+++ b/src/schema.sql
@@ -3,7 +3,7 @@ CREATE TYPE protocol AS ENUM('HTTP/1.0', 'HTTP/1.1', 'HTTP/1.2', 'HTTP/1.3', 'HT
CREATE TYPE entity AS ENUM('host', 'virtual_host', 'path', 'query_string', 'referrer', 'user_agent', 'unparsable_line');
CREATE TABLE entities (
- id bigint NOT NULL,
+ id oid NOT NULL,
value text NOT NULL,
type entity NOT NULL,
detail jsonb,
@@ -14,19 +14,19 @@ CREATE TABLE entities (
CREATE TABLE access_log (
id bigint GENERATED ALWAYS AS IDENTITY,
- hostname bigint NOT NULL,
- virtual_host bigint NOT NULL,
+ hostname oid NOT NULL,
+ virtual_host oid NOT NULL,
remoteip inet NOT NULL,
request_time timestamp(6) NOT NULL,
method http_verb NOT NULL,
protocol protocol NOT NULL,
- path bigint NOT NULL,
- query_string bigint,
+ path oid NOT NULL,
+ query_string oid,
status smallint NOT NULL,
size int NOT NULL,
duration interval second(6) NOT NULL,
- referrer bigint,
- user_agent bigint,
+ referrer oid,
+ user_agent oid,
CONSTRAINT pk_access_log PRIMARY KEY(id),
CONSTRAINT fk_access_log_hostname FOREIGN KEY(hostname) REFERENCES entities(id),
diff --git a/test/test-ingest.cpp b/test/test-ingest.cpp
index f86dd25..73a37c6 100644
--- a/test/test-ingest.cpp
+++ b/test/test-ingest.cpp
@@ -278,11 +278,11 @@ BOOST_AUTO_TEST_CASE(DiscardUnparsable)
{
BOOST_REQUIRE_NO_THROW(ingestLogLine("does not parse"));
auto dbconn = dbpool->get();
- auto select = dbconn->select("SELECT id, value FROM entities WHERE type = 'unparsable_line'");
- constexpr std::array<std::tuple<uint64_t, std::string_view>, 1> EXPECTED {{
+ auto select = dbconn->select("SELECT id::bigint, value FROM entities WHERE type = 'unparsable_line'");
+ constexpr std::array<std::tuple<Crc32Value, std::string_view>, 1> EXPECTED {{
{1664299262, "does not parse"},
}};
- auto rows = select->as<uint64_t, std::string_view>();
+ auto rows = select->as<Crc32Value, std::string_view>();
BOOST_CHECK_EQUAL_COLLECTIONS(rows.begin(), rows.end(), EXPECTED.begin(), EXPECTED.end());
}