From fc41c871b2fdac3db69e4e998dac9a1c9591d1fe Mon Sep 17 00:00:00 2001 From: Jonathan Dance Date: Tue, 23 Jan 2024 17:18:55 -0600 Subject: [PATCH 1/3] failing tests for bug using with tables --- .gitignore | 4 ++-- expected/equality.out | 24 +++++++++++++++++++++++- expected/strstr.out | 26 ++++++++++++++++++++++++-- sql/equality.sql | 19 ++++++++++++++++++- sql/strstr.sql | 19 ++++++++++++++++++- 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8aec885..6614645 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ *.o .clangd -results - +/results +/regression.* diff --git a/expected/equality.out b/expected/equality.out index f2e2f20..dc54155 100644 --- a/expected/equality.out +++ b/expected/equality.out @@ -1,4 +1,4 @@ -CREATE EXTENSION stringtheory; +CREATE EXTENSION IF NOT EXISTS stringtheory; -- no match SELECT stringtheory.equals('hello', 'world'); equals @@ -27,3 +27,25 @@ SELECT stringtheory.equals('123456', '12345'); f (1 row) +-- test equality in a CTE +WITH a AS (SELECT md5(generate_series(1, 1000)::text) b) +SELECT count(*) FROM a +WHERE stringtheory.equals(b, md5('123')); + count +------- + 1 +(1 row) + +-- test strstr in a table +CREATE TEMPORARY TABLE stringtheory_test +(a text); +INSERT INTO stringtheory_test +SELECT md5(generate_series(1,1000)::text); +SELECT COUNT(*) FROM stringtheory_test +WHERE stringtheory.equals(a, md5('123')); + count +------- + 1 +(1 row) + +DROP TABLE stringtheory_test; diff --git a/expected/strstr.out b/expected/strstr.out index a4d72f1..ccef889 100644 --- a/expected/strstr.out +++ b/expected/strstr.out @@ -1,5 +1,5 @@ -CREATE EXTENSION stringtheory; -ERROR: extension "stringtheory" already exists +CREATE EXTENSION IF NOT EXISTS stringtheory; +NOTICE: extension "stringtheory" already exists, skipping -- no match SELECT stringtheory.strstr('hello', 'world'); strstr @@ -42,3 +42,25 @@ SELECT stringtheory.strstr('ello', 'hello world'); -1 (1 row) +-- test strstr in a CTE +WITH a AS (SELECT md5(generate_series(1, 1000)::text) b) +SELECT COUNT(*) FROM a +WHERE stringtheory.strstr(b, '00') >= 0; + count +------- + 114 +(1 row) + +-- test strstr in a table +CREATE TEMPORARY TABLE stringtheory_test +(a text); +INSERT INTO stringtheory_test +SELECT md5(generate_series(1,1000)::text); +SELECT COUNT(*) FROM stringtheory_test +WHERE stringtheory.strstr(a, '00') >= 0; + count +------- + 114 +(1 row) + +DROP TABLE stringtheory_test; diff --git a/sql/equality.sql b/sql/equality.sql index f7eafd7..bd87fc8 100644 --- a/sql/equality.sql +++ b/sql/equality.sql @@ -1,4 +1,4 @@ -CREATE EXTENSION stringtheory; +CREATE EXTENSION IF NOT EXISTS stringtheory; -- no match SELECT stringtheory.equals('hello', 'world'); @@ -11,3 +11,20 @@ SELECT stringtheory.equals('1234567890123456', '1234567890123456'); -- no match when partial SELECT stringtheory.equals('123456', '12345'); + +-- test equality in a CTE +WITH a AS (SELECT md5(generate_series(1, 1000)::text) b) +SELECT count(*) FROM a +WHERE stringtheory.equals(b, md5('123')); + +-- test strstr in a table +CREATE TEMPORARY TABLE stringtheory_test +(a text); + +INSERT INTO stringtheory_test +SELECT md5(generate_series(1,1000)::text); + +SELECT COUNT(*) FROM stringtheory_test +WHERE stringtheory.equals(a, md5('123')); + +DROP TABLE stringtheory_test; diff --git a/sql/strstr.sql b/sql/strstr.sql index 3be7e7d..3fdb080 100644 --- a/sql/strstr.sql +++ b/sql/strstr.sql @@ -1,4 +1,4 @@ -CREATE EXTENSION stringtheory; +CREATE EXTENSION IF NOT EXISTS stringtheory; -- no match SELECT stringtheory.strstr('hello', 'world'); @@ -17,3 +17,20 @@ SELECT stringtheory.strstr('hello world', 'ello'); -- haystack in needle not found SELECT stringtheory.strstr('ello', 'hello world'); + +-- test strstr in a CTE +WITH a AS (SELECT md5(generate_series(1, 1000)::text) b) +SELECT COUNT(*) FROM a +WHERE stringtheory.strstr(b, '00') >= 0; + +-- test strstr in a table +CREATE TEMPORARY TABLE stringtheory_test +(a text); + +INSERT INTO stringtheory_test +SELECT md5(generate_series(1,1000)::text); + +SELECT COUNT(*) FROM stringtheory_test +WHERE stringtheory.strstr(a, '00') >= 0; + +DROP TABLE stringtheory_test; From fe8c54ce24bb69d5821a82e7ad15eb3d1f101f6a Mon Sep 17 00:00:00 2001 From: Jonathan Dance Date: Tue, 23 Jan 2024 17:29:20 -0600 Subject: [PATCH 2/3] tweaks for CI --- .github/workflows/build_and_test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 488d37f..63624d4 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,10 +1,18 @@ name: pg_stringtheory Build and Test on: push: - pull_request: + paths: + - '.github/**' + - 'src/**' + - 'expected/**' + - 'sql/**' + - '*.control' + - '*.sql' + - Makefile jobs: build-and-test: strategy: + fail-fast: false matrix: os: [ubuntu-latest] version: [REL_14_STABLE, REL_15_STABLE, REL_16_STABLE] From a41bcf758f159556f1d6aa7d82ea3a275673a701 Mon Sep 17 00:00:00 2001 From: Jerry Sievert Date: Wed, 24 Jan 2024 19:27:55 -0800 Subject: [PATCH 3/3] tests passing --- src/text.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/text.cpp b/src/text.cpp index a2b90b3..d24900c 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -2,6 +2,8 @@ extern "C" { #include "postgres.h" #include "fmgr.h" +#include "mb/pg_wchar.h" + #if PG_VERSION_NUM >= 160000 #include "varatt.h" #endif @@ -73,7 +75,8 @@ Datum pg_strstr(PG_FUNCTION_ARGS) { } /* Get the results from the simd functions. */ - size_t ret = fast_strstr(VARDATA(left), len_left, VARDATA(right), len_right); + size_t ret = + fast_strstr(VARDATA_ANY(left), len_left, VARDATA_ANY(right), len_right); PG_RETURN_INT32(ret); } @@ -98,7 +101,8 @@ Datum pg_equals(PG_FUNCTION_ARGS) { } /* Get the results from the simd functions. */ - size_t ret = fast_strstr(VARDATA(left), len_left, VARDATA(right), len_right); + size_t ret = + fast_strstr(VARDATA_ANY(left), len_left, VARDATA_ANY(right), len_right); /* If the result is 0, strings are equal. */ PG_RETURN_BOOL(ret == 0);