Исходный код СУБД 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
-- 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
);
 
-- 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;
 
-- 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;
 
-- 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;
 
-- 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;
 
-- 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;
 
-- 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;
 
-- 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;
 
-- Clean up
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'edge_test_content_chunks';
SELECT pgedge_vectorizer.disable_vectorization('edge_test'::regclass, 'content', true);
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'
);
 
-- 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;
 
-- Verify queue entries exist
SELECT COUNT(*) > 0 AS queue_entries FROM pgedge_vectorizer.queue
WHERE chunk_table = 'custom_pk_test_body_chunks';
 
-- 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);
DROP TABLE custom_pk_test;