Исходный код СУБД 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
-- Edge cases test
-- This test verifies handling of edge cases
-- Create a test table
CREATE TABLE edge_test (
    id BIGSERIAL PRIMARY KEY,
    content TEXT
);
-- Enable vectorization
SELECT pgedge_vectorizer.enable_vectorization(
    'edge_test'::regclass,
    'content',
    'token_based',
    100,
    10,
    1536
);
NOTICE:  Using primary key column: id (bigint)
NOTICE:  Vectorization enabled: edge_test -> edge_test_content_chunks
NOTICE:  Strategy: token_based, chunk_size: 100, overlap: 10
NOTICE:  Processing existing rows...
NOTICE:  Processed 0 existing rows
 enable_vectorization 
----------------------
 
(1 row)
 
-- Test 1: Empty string (should not create chunks)
INSERT INTO edge_test (content) VALUES ('');
SELECT COUNT(*) AS chunks_for_empty FROM edge_test_content_chunks WHERE source_id = 1;
 chunks_for_empty 
------------------
                0
(1 row)
 
-- Test 2: NULL value (should not create chunks)
INSERT INTO edge_test (content) VALUES (NULL);
SELECT COUNT(*) AS chunks_for_null FROM edge_test_content_chunks WHERE source_id = 2;
 chunks_for_null 
-----------------
               0
(1 row)
 
-- Test 3: Whitespace only (should not create chunks)
INSERT INTO edge_test (content) VALUES ('   ');
SELECT COUNT(*) AS chunks_for_whitespace FROM edge_test_content_chunks WHERE source_id = 3;
 chunks_for_whitespace 
-----------------------
                     0
(1 row)
 
-- Test 4: Single word (should create 1 chunk)
INSERT INTO edge_test (content) VALUES ('Word');
SELECT COUNT(*) AS chunks_for_word FROM edge_test_content_chunks WHERE source_id = 4;
 chunks_for_word 
-----------------
               1
(1 row)
 
-- Test 5: Very long text (should create multiple chunks)
INSERT INTO edge_test (content)
VALUES (repeat('This is a test sentence that will be repeated to create a very long document. ', 100));
SELECT COUNT(*) > 1 AS multiple_chunks FROM edge_test_content_chunks WHERE source_id = 5;
 multiple_chunks 
-----------------
 t
(1 row)
 
-- Test 6: Update to empty (should delete chunks)
UPDATE edge_test SET content = '' WHERE id = 4;
SELECT COUNT(*) AS chunks_after_empty_update FROM edge_test_content_chunks WHERE source_id = 4;
 chunks_after_empty_update 
---------------------------
                         0
(1 row)
 
-- Test 7: Update NULL to content (should create chunks)
UPDATE edge_test SET content = 'New content' WHERE id = 2;
SELECT COUNT(*) > 0 AS chunks_after_null_update FROM edge_test_content_chunks WHERE source_id = 2;
 chunks_after_null_update 
--------------------------
 t
(1 row)
 
-- Clean up
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'edge_test_content_chunks';
SELECT pgedge_vectorizer.disable_vectorization('edge_test'::regclass, 'content', true);
NOTICE:  Vectorization disabled and chunk table dropped: edge_test_content_chunks
 disable_vectorization 
-----------------------
 
(1 row)
 
DROP TABLE edge_test;
-- Test 8: Custom primary key column name
CREATE TABLE custom_pk_test (
    doc_id BIGSERIAL PRIMARY KEY,
    body TEXT
);
SELECT pgedge_vectorizer.enable_vectorization(
    'custom_pk_test'::regclass,
    'body',
    'token_based',
    100,
    10,
    1536,
    NULL,
    'doc_id'
);
NOTICE:  Using primary key column: doc_id (bigint)
NOTICE:  Vectorization enabled: custom_pk_test -> custom_pk_test_body_chunks
NOTICE:  Strategy: token_based, chunk_size: 100, overlap: 10
NOTICE:  Processing existing rows...
NOTICE:  Processed 0 existing rows
 enable_vectorization 
----------------------
 
(1 row)
 
-- Insert a document using the custom PK
INSERT INTO custom_pk_test (body)
VALUES ('This document uses a custom primary key column.');
-- Verify chunks were created with correct source_id
SELECT COUNT(*) > 0 AS chunks_created FROM custom_pk_test_body_chunks WHERE source_id = 1;
 chunks_created 
----------------
 t
(1 row)
 
-- Verify queue entries exist
SELECT COUNT(*) > 0 AS queue_entries FROM pgedge_vectorizer.queue
WHERE chunk_table = 'custom_pk_test_body_chunks';
 queue_entries 
---------------
 t
(1 row)
 
-- Update the document (should recreate chunks)
UPDATE custom_pk_test SET body = 'Updated body text.' WHERE doc_id = 1;
-- Clean up
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'custom_pk_test_body_chunks';
SELECT pgedge_vectorizer.disable_vectorization('custom_pk_test'::regclass, 'body', true);
NOTICE:  Vectorization disabled and chunk table dropped: custom_pk_test_body_chunks
 disable_vectorization 
-----------------------
 
(1 row)
 
DROP TABLE custom_pk_test;