Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-10-06 6bac54b555d27f1a85c1e4f011a6e7bd9111b0d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Vectorization test
-- This test verifies enable/disable vectorization functionality
 
-- Create a test table
CREATE TABLE test_docs (
    id BIGSERIAL PRIMARY KEY,
    title TEXT,
    content TEXT
);
 
-- Enable vectorization
SELECT pgedge_vectorizer.enable_vectorization(
    'test_docs'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
 
-- Verify chunk table was created
SELECT tablename FROM pg_tables
WHERE tablename = 'test_docs_content_chunks';
 
-- Verify trigger was created
SELECT tgname FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
 
-- Insert a test document
INSERT INTO test_docs (title, content)
VALUES ('Test Document', 'This is a test document with some content for testing the vectorization functionality.');
 
-- Verify chunks were created
SELECT COUNT(*) > 0 AS chunks_created FROM test_docs_content_chunks;
 
-- Verify queue entries were created
SELECT COUNT(*) > 0 AS queue_entries_created
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'test_docs_content_chunks';
 
-- Test update (should recreate chunks)
UPDATE test_docs SET content = 'Updated content for the test document.' WHERE id = 1;
 
-- Disable vectorization
SELECT pgedge_vectorizer.disable_vectorization('test_docs'::regclass, 'content', false);
 
-- Verify trigger was dropped
SELECT COUNT(*) AS trigger_count FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
 
-- Verify queue items were cleaned up
SELECT COUNT(*) AS orphaned_queue_items
FROM pgedge_vectorizer.queue
WHERE chunk_table = 'test_docs_content_chunks'
AND status IN ('pending', 'processing');
 
-- Re-enable vectorization with existing chunk table (should not fail)
SELECT pgedge_vectorizer.enable_vectorization(
    'test_docs'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
 
-- Verify trigger was re-created
SELECT tgname FROM pg_trigger
WHERE tgname LIKE '%test_docs%vectorization%';
 
-- Verify chunks still exist (upserted, not duplicated)
SELECT COUNT(*) AS chunk_count FROM test_docs_content_chunks;
 
-- Clean up
SELECT pgedge_vectorizer.disable_vectorization('test_docs'::regclass, 'content', true);
DROP TABLE test_docs;