Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subdir =
top_builddir = .
include $(top_builddir)/src/Makefile.global

$(call recurse,all install,src config contrib/ivorysql_ora contrib/ora_btree_gist contrib/ora_btree_gin)
$(call recurse,all install,src config contrib/ivorysql_ora contrib/uuid-ossp contrib/ora_btree_gist contrib/ora_btree_gin)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify no duplicate recursion/builds for contrib/uuid-ossp.

You added contrib/uuid-ossp to top-level recurse targets alongside contrib. If contrib already enumerates uuid-ossp, this could double-build/clean/test. If not, this is fine.

If uuid-ossp is already in contrib’s SUBDIRS, consider removing the explicit contrib/uuid-ossp entries here to avoid duplicate recursion. Otherwise, keep as-is.

Also applies to: 48-48, 98-98


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Does contrib/Makefile include uuid-ossp?
fd -a contrib/Makefile
if fd -a contrib/Makefile >/dev/null; then
  rg -n "SUBDIRS|DIRS" contrib/Makefile -A2 -B2
  rg -n "uuid-ossp" contrib/Makefile || echo "uuid-ossp not listed in contrib/Makefile"
else
  echo "contrib/Makefile not found"
fi

Length of output: 1067


Remove duplicate recursion for contrib/uuid-ossp

The contrib/Makefile already adds uuid-ossp to SUBDIRS/ALWAYS_SUBDIRS, so having it explicitly in the top‐level recurse call will double-build/clean/test. Please remove the extra entries at lines 11, 48, and 98 in GNUmakefile.in.

  • GNUmakefile.in:11,48,98
    -$(call recurse,all install,src config contrib/ivorysql_ora contrib/uuid-ossp contrib/ora_btree_gist contrib/ora_btree_gin)
    +$(call recurse,all install,src config contrib/ivorysql_ora contrib/ora_btree_gist contrib/ora_btree_gin)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$(call recurse,all install,src config contrib/ivorysql_ora contrib/uuid-ossp contrib/ora_btree_gist contrib/ora_btree_gin)
$(call recurse,all install,src config contrib/ivorysql_ora contrib/ora_btree_gist contrib/ora_btree_gin)
🤖 Prompt for AI Agents
In GNUmakefile.in at lines 11, 48, and 98, the contrib/uuid-ossp directory is
redundantly included in the recurse calls, causing duplicate build, clean, and
test actions. Remove the explicit mentions of contrib/uuid-ossp from these lines
to avoid double-processing since it is already handled by the contrib/Makefile's
SUBDIRS/ALWAYS_SUBDIRS settings.

Copy link
Copy Markdown
Collaborator

@OreoYang OreoYang Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why this file was modified?

Copy link
Copy Markdown
Contributor Author

@Carlos-Chong200 Carlos-Chong200 Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @OreoYang
The modification of this line is to automatically compile the uuid-ossp plugin with the aim of automatically loading the plugin for using the sys_guid function.
If "uuid - ossp" is removed, the following error message will be reported when executing initdb, indicating that uuid - ossp has not been compiled correctly.
c17d5307-a959-4d5a-8cb9-7240ab064fd7

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's make sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Carlos-Chong200 @OreoYang

Question has raised in the past about UUID function "in-core" or not (on psql-hackers). OSSP was on the topic.

It's a bit surprising to have dependency on contrib/extensions for initdb, does it make sense to make requirement closer to postgres kernel by moving required functions outside of contrib/ ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Cedric,

In addition to uuid extension, there are other extensions that are created in initdb, like plisql, ivorysql_ora.
This is IvorySQL's design and we try to develop Oracle compatibility features in extensions for flexibility.


docs:
$(MAKE) -C doc all
Expand Down Expand Up @@ -45,7 +45,7 @@ $(call recurse,coverage,doc src config contrib)

# clean, distclean, etc should apply to contrib too, even though
# it's not built by default
$(call recurse,clean,doc contrib contrib/ivorysql_ora contrib/ora_btree_gist contrib/ora_btree_gin src config)
$(call recurse,clean,doc contrib contrib/ivorysql_ora contrib/uuid-ossp contrib/ora_btree_gist contrib/ora_btree_gin src config)
clean:
rm -rf tmp_install/ portlock/
# Garbage from autoconf:
Expand Down Expand Up @@ -95,7 +95,7 @@ GNUmakefile: GNUmakefile.in $(top_builddir)/config.status

$(call recurse,oracle-pg-check-world,src/test,oracle-pg-check)
#add oracle regression
$(call recurse,oracle-check-world,src/oracle_test src/pl src/interfaces/ecpg src/interfaces/libpq/ivytest contrib contrib/ivorysql_ora contrib/ora_btree_gist contrib/ora_btree_gin src/bin,oracle-check)
$(call recurse,oracle-check-world,src/oracle_test src/pl src/interfaces/ecpg src/interfaces/libpq/ivytest contrib contrib/ivorysql_ora contrib/uuid-ossp contrib/ora_btree_gist contrib/ora_btree_gin src/bin,oracle-check)
$(call recurse,oracle-checkprep, src/oracle_test src/pl src/interfaces/ecpg contrib src/bin)

$(call recurse,oracle-installcheck-world,src/oracle_test src/pl src/interfaces/ecpg contrib src/bin,oracle-installcheck)
Expand Down
5 changes: 5 additions & 0 deletions contrib/ivorysql_ora/preload_ora_misc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ CREATE TYPE sys.urowid AS(rowoid OID, rowno bigint);

CREATE CAST (sys.rowid AS sys.urowid) WITH INOUT AS IMPLICIT;
CREATE CAST (sys.urowid AS sys.rowid) WITH INOUT AS IMPLICIT;

--
-- Plugin uuid-ossp
--
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
Comment on lines +16 to +20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Don't CREATE EXTENSION while search_path is set to sys (objects will be installed into sys).

At this point search_path=sys; CREATE EXTENSION without SCHEMA will place extension objects (e.g., uuid_generate_*) into sys, not public. That can break lookups/tests expecting these functions on the default path and pollutes the sys schema.

Recommend creating the extension with search_path reset to default (public), then restore sys:

 --
 -- Plugin uuid-ossp
 --
-CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+RESET search_path;          -- ensure extension installs into public
+CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+SET search_path TO sys;     -- restore Oracle compatibility path

Alternatively (if the extension is relocatable), you can force it into public:

  • CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA public;

Run to confirm relocatable status and avoid the SCHEMA clause if false, and to ensure default_version is 1.1:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Locate control file and check 'relocatable' and 'default_version'
fd -a uuid-ossp.control | tee /dev/stderr
if fd -a uuid-ossp.control >/dev/null; then
  rg -n "^(relocatable|default_version)\s*=" $(fd -a uuid-ossp.control)
else
  echo "uuid-ossp.control not found under contrib/uuid-ossp" >&2
fi

Length of output: 157


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the uuid-ossp control file
control_file=$(fd -a uuid-ossp.control || true)
if [[ -z "$control_file" ]]; then
  echo "uuid-ossp.control not found in the repo" >&2
  exit 1
fi

echo "Found control file: $control_file"

# Print relocatable and default_version settings
rg -n "^(relocatable|default_version)\s*=" "$control_file"

Length of output: 488


Ensure uuid-ossp Installs into the Public Schema
The CREATE EXTENSION call currently runs with search_path=sys, so all objects (e.g., uuid_generate_*) land in the sys schema. To avoid polluting sys and breaking clients/tests that expect these functions in the default path, install the extension into public.

We’ve confirmed from contrib/uuid-ossp/uuid-ossp.control that

  • default_version = '1.1'
  • relocatable = true

You can address this in one of two ways:

• Reset the search_path around the CREATE:

--
-- Plugin uuid-ossp
--
- CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+ RESET search_path;                     -- ensure objects go into public
+ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
+ SET search_path TO sys;                -- restore Oracle-compat path

• Or, since the extension is relocatable, force it into public:

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA public;

Pick the approach that best fits your code-style guidelines.

🤖 Prompt for AI Agents
In contrib/ivorysql_ora/preload_ora_misc.sql around lines 16 to 20, the CREATE
EXTENSION for uuid-ossp currently installs objects into the sys schema due to
the search_path setting. To fix this, modify the CREATE EXTENSION statement to
explicitly install the extension into the public schema by adding "SCHEMA
public" to the command, ensuring the uuid_generate_* functions and related
objects reside in the public schema and avoid polluting sys.

7 changes: 7 additions & 0 deletions contrib/uuid-ossp/expected/ivy_uuid_ossp.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP EXTENSION IF EXISTS "uuid-ossp" CASCADE;
CREATE EXTENSION "uuid-ossp";
SELECT uuid_nil();
uuid_nil
Expand Down Expand Up @@ -143,3 +144,9 @@ SELECT uuid_generate_v4() <> uuid_generate_v4();
t
(1 row)

SELECT sys_guid() <> sys_guid();
?column?
----------
t
(1 row)

3 changes: 3 additions & 0 deletions contrib/uuid-ossp/sql/ivy_uuid_ossp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP EXTENSION IF EXISTS "uuid-ossp" CASCADE;
CREATE EXTENSION "uuid-ossp";

SELECT uuid_nil();
Expand Down Expand Up @@ -79,3 +80,5 @@ SELECT uuid_version_bits(uuid_generate_v4()),
uuid_reserved_bits(uuid_generate_v4());

SELECT uuid_generate_v4() <> uuid_generate_v4();

SELECT sys_guid() <> sys_guid();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need also change corresponding expected/ivy_uuid_ossp.out, otherwise the regression test would fail.

5 changes: 5 additions & 0 deletions contrib/uuid-ossp/uuid-ossp--1.0--1.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ ALTER FUNCTION uuid_generate_v1mc() PARALLEL SAFE;
ALTER FUNCTION uuid_generate_v3(uuid, text) PARALLEL SAFE;
ALTER FUNCTION uuid_generate_v4() PARALLEL SAFE;
ALTER FUNCTION uuid_generate_v5(uuid, text) PARALLEL SAFE;

CREATE OR REPLACE FUNCTION pg_catalog.sys_guid()
RETURNS bytea
AS 'MODULE_PATHNAME', 'ora_sys_guid'
VOLATILE STRICT LANGUAGE C;
5 changes: 5 additions & 0 deletions contrib/uuid-ossp/uuid-ossp--1.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ CREATE FUNCTION uuid_generate_v5(namespace uuid, name text)
RETURNS uuid
AS 'MODULE_PATHNAME', 'uuid_generate_v5'
IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE;

CREATE OR REPLACE FUNCTION pg_catalog.sys_guid()
RETURNS bytea
AS 'MODULE_PATHNAME', 'ora_sys_guid'
VOLATILE STRICT LANGUAGE C;
39 changes: 38 additions & 1 deletion contrib/uuid-ossp/uuid-ossp.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ do { \

#endif /* !HAVE_UUID_OSSP */

/** The byte length of the value returned by ora_sys_guid **/
#define SYS_GUID_LENGTH 16

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(uuid_nil);
Expand All @@ -115,7 +118,7 @@ PG_FUNCTION_INFO_V1(uuid_generate_v1mc);
PG_FUNCTION_INFO_V1(uuid_generate_v3);
PG_FUNCTION_INFO_V1(uuid_generate_v4);
PG_FUNCTION_INFO_V1(uuid_generate_v5);

PG_FUNCTION_INFO_V1(ora_sys_guid);
#ifdef HAVE_UUID_OSSP

static void
Expand Down Expand Up @@ -550,3 +553,37 @@ uuid_generate_v5(PG_FUNCTION_ARGS)
VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name));
#endif
}


Datum
ora_sys_guid(PG_FUNCTION_ARGS)
{
bytea *result;
result = (bytea *)palloc(VARHDRSZ + SYS_GUID_LENGTH);
SET_VARSIZE(result, VARHDRSZ + SYS_GUID_LENGTH);

#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
uuid = get_cached_uuid_t(0);
rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
if (rc != UUID_RC_OK) {
pguuid_complain(rc);
}
memcpy(VARDATA(result), (unsigned char *)uuid, SYS_GUID_LENGTH);

Comment on lines +565 to +574
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: OSSP uuid_t is an opaque handle; memcpy does not yield the UUID bytes

With OSSP, uuid_t is not a 16-byte binary UUID. You must export the generated UUID to binary via uuid_export; memcpy-ing from the uuid_t object produces invalid results.

Apply:

 #ifdef HAVE_UUID_OSSP
-    uuid_t      *uuid;
-    uuid_rc_t   rc;
-    uuid = get_cached_uuid_t(0);
-    rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
-    if (rc != UUID_RC_OK) {
-        pguuid_complain(rc);
-    }
-    memcpy(VARDATA(result), (unsigned char *)uuid, SYS_GUID_LENGTH);
+    uuid_t      *uuid;
+    uuid_rc_t   rc;
+    void       *ptr = VARDATA(result);
+    size_t      len = SYS_GUID_LENGTH;
+
+    uuid = get_cached_uuid_t(0);
+    rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
+    if (rc != UUID_RC_OK)
+        pguuid_complain(rc);
+    rc = uuid_export(uuid, UUID_FMT_BIN, &ptr, &len);
+    if (rc != UUID_RC_OK || len != SYS_GUID_LENGTH)
+        pguuid_complain(rc);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
uuid = get_cached_uuid_t(0);
rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
if (rc != UUID_RC_OK) {
pguuid_complain(rc);
}
memcpy(VARDATA(result), (unsigned char *)uuid, SYS_GUID_LENGTH);
#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
void *ptr = VARDATA(result);
size_t len = SYS_GUID_LENGTH;
uuid = get_cached_uuid_t(0);
rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
if (rc != UUID_RC_OK)
pguuid_complain(rc);
rc = uuid_export(uuid, UUID_FMT_BIN, &ptr, &len);
if (rc != UUID_RC_OK || len != SYS_GUID_LENGTH)
pguuid_complain(rc);
🤖 Prompt for AI Agents
In contrib/uuid-ossp/uuid-ossp.c around lines 565 to 574, the code incorrectly
uses memcpy to copy the UUID from the opaque uuid_t handle, which does not
contain raw UUID bytes. To fix this, replace the memcpy call with a call to
uuid_export to convert the uuid_t to a 16-byte binary UUID before copying it
into the result buffer.

#elif defined(HAVE_UUID_E2FS)
uuid_t uu;
uuid_generate_random(uu);
memcpy(VARDATA(result), uu, SYS_GUID_LENGTH);

#else /* BSD */
int i;
unsigned char byte_array[SYS_GUID_LENGTH];
for (i = 0; i < SYS_GUID_LENGTH; i++) {
byte_array[i] = (unsigned char)arc4random();
}
memcpy(VARDATA(result), byte_array, SYS_GUID_LENGTH);
#endif
PG_RETURN_BYTEA_P(result);
}
Loading