[PR #32273] Fix/analyticdb vector initialize sql #33643

Open
opened 2026-02-21 20:53:39 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/32273

State: open
Merged: No


Summary

This PR improves AnalyticDB vector store initialization when using SQL mode (ANALYTICDB_HOST configured).

Changes:

  1. to_tsquery_from_text initialization
    Wrap CREATE OR REPLACE FUNCTION public.to_tsquery_from_text in a PL/pgSQL DO block and catch insufficient_privilege via SQLSTATE '42501'. Initialization now succeeds when the function already exists and the current database user is not the owner (e.g. has only EXECUTE on the function), avoiding failures in managed/shared AnalyticDB environments.

  2. ANN vector index options
    Remove external_storage=0 from the CREATE INDEX ... USING ann(vector) options to improve compatibility with AnalyticDB versions or configurations where this option is not supported or has been deprecated.

Motivation:
When Dify runs as a non-superuser or when the function is pre-created by an admin, the previous direct CREATE OR REPLACE FUNCTION could raise a privilege error and block vector DB setup. Using SQLSTATE '42501' is more portable than the named exception in some PostgreSQL-derived engines (e.g. AnalyticDB).

Fixes #32271

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/32273 **State:** open **Merged:** No --- ## Summary This PR improves AnalyticDB vector store initialization when using SQL mode (`ANALYTICDB_HOST` configured). **Changes:** 1. **to_tsquery_from_text initialization** Wrap `CREATE OR REPLACE FUNCTION public.to_tsquery_from_text` in a PL/pgSQL `DO` block and catch `insufficient_privilege` via `SQLSTATE '42501'`. Initialization now succeeds when the function already exists and the current database user is not the owner (e.g. has only `EXECUTE` on the function), avoiding failures in managed/shared AnalyticDB environments. 2. **ANN vector index options** Remove `external_storage=0` from the `CREATE INDEX ... USING ann(vector)` options to improve compatibility with AnalyticDB versions or configurations where this option is not supported or has been deprecated. **Motivation:** When Dify runs as a non-superuser or when the function is pre-created by an admin, the previous direct `CREATE OR REPLACE FUNCTION` could raise a privilege error and block vector DB setup. Using `SQLSTATE '42501'` is more portable than the named exception in some PostgreSQL-derived engines (e.g. AnalyticDB). Fixes #32271 ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:53:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33643