• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codenotary / immudb / 24841644892

23 Apr 2026 02:44PM UTC coverage: 85.279% (-4.0%) from 89.306%
24841644892

push

gh-ci

web-flow
feat: v1.11.0 PostgreSQL compatibility and SQL feature expansion (#2090)

* Add structured audit logging with immutable audit trail

Introduces a new --audit-log flag that records all gRPC operations as
structured JSON events in immudb's tamper-proof KV store. Events are
stored under the audit: key prefix in systemdb, queryable via Scan and
verifiable via VerifiableGet. An async buffered writer ensures minimal
latency impact. Configurable event filtering (all/write/admin) via
--audit-log-events flag.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add PostgreSQL ORM compatibility layer and verification functions

Extend the pgsql wire protocol with immudb verification functions
(immudb_state, immudb_verify_row, immudb_verify_tx, immudb_history,
immudb_tx) accessible via standard SQL SELECT statements.

Add pg_catalog resolvers (pg_attribute, pg_index, pg_constraint,
pg_type, pg_settings, pg_description) and information_schema
resolvers (tables, columns, schemata, key_column_usage) to support
ORM introspection from Django, SQLAlchemy, GORM, and ActiveRecord.

Add PostgreSQL compatibility functions: current_database,
current_schema, current_user, format_type, pg_encoding_to_char,
pg_get_expr, pg_get_constraintdef, obj_description, col_description,
has_table_privilege, has_schema_privilege, and others.

Add SHOW statement emulation for common ORM config queries and
schema-qualified name stripping for information_schema and public
schema references.

* Implement EXISTS and IN subquery support in SQL engine

Replace the previously stubbed ExistsBoolExp and InSubQueryExp
implementations with working non-correlated subquery execution.

EXISTS subqueries resolve the inner SELECT and check if any rows
are returned. IN subqueries resolve the inner SELECT, iterate the
result set, and compare each value against the outer expression.
Both support NOT variants (NOT EXISTS, NOT IN).

Correlated subqueries (referencing outer query columns) ar... (continued)

7254 of 10471 new or added lines in 124 files covered. (69.28%)

115 existing lines in 18 files now uncovered.

44599 of 52298 relevant lines covered (85.28%)

127676.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/pkg/pgsql/sys/pg_indexes.go
1
/*
2
Copyright 2026 Codenotary Inc. All rights reserved.
3

4
SPDX-License-Identifier: BUSL-1.1
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    https://mariadb.com/bsl11/
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package sys
18

19
import (
20
        "context"
21
        "fmt"
22
        "strings"
23

24
        "github.com/codenotary/immudb/embedded/sql"
25
)
26

27
// pg_indexes: one row per index on a user table. ORMs (XORM, GORM,
28
// Hibernate) read this to enumerate indexes; pgAdmin's object browser
29
// renders from it. The indexdef column holds a synthesised
30
// CREATE INDEX statement good enough for "does this index cover X"
31
// checks — real PG returns the original CREATE source, but immudb
32
// doesn't persist DDL text.
33
//
34
// Column shape mirrors the legacy handlePgIndexesQuery canned handler
35
// (pgadmin_compat.go:857). The naming convention <table>_idx_<id>
36
// matches the old handler so tests pinning that name keep working.
37
func init() {
13✔
38
        sql.RegisterSystemTable(&sql.SystemTableDef{
13✔
39
                Name: "pg_indexes",
13✔
40
                Columns: []sql.SystemTableColumn{
13✔
41
                        {Name: "schemaname", Type: sql.VarcharType, MaxLen: 64},
13✔
42
                        {Name: "tablename", Type: sql.VarcharType, MaxLen: 128},
13✔
43
                        {Name: "indexname", Type: sql.VarcharType, MaxLen: 128},
13✔
44
                        {Name: "tablespace", Type: sql.VarcharType, MaxLen: 64},
13✔
45
                        {Name: "indexdef", Type: sql.VarcharType, MaxLen: 1024},
13✔
46
                        // Synthesised PK: indexname is per-schema but registry
13✔
47
                        // wants a single column, so use a synthetic oid.
13✔
48
                        {Name: "index_oid", Type: sql.IntegerType},
13✔
49
                },
13✔
50
                PKColumn: "index_oid",
13✔
51
                Scan: func(ctx context.Context, tx *sql.SQLTx) ([]*sql.Row, error) {
16✔
52
                        cat := tx.Catalog()
3✔
53
                        if cat == nil {
3✔
NEW
54
                                return nil, nil
×
NEW
55
                        }
×
56
                        tables := cat.GetTables()
3✔
57
                        rows := make([]*sql.Row, 0, len(tables))
3✔
58
                        for _, t := range tables {
6✔
59
                                for _, idx := range t.GetIndexes() {
8✔
60
                                        indexName := fmt.Sprintf("%s_idx_%d", t.Name(), idx.ID())
5✔
61
                                        rows = append(rows, &sql.Row{ValuesByPosition: []sql.TypedValue{
5✔
62
                                                sql.NewVarchar("public"),
5✔
63
                                                sql.NewVarchar(t.Name()),
5✔
64
                                                sql.NewVarchar(indexName),
5✔
65
                                                sql.NewVarchar("pg_default"),
5✔
66
                                                sql.NewVarchar(pgIndexesIndexDef(t.Name(), idx)),
5✔
67
                                                sql.NewInteger(relOID("pg_indexes", indexName)),
5✔
68
                                        }})
5✔
69
                                }
5✔
70
                        }
71
                        return rows, nil
3✔
72
                },
73
        })
74
}
75

76
// pgIndexesIndexDef synthesises a CREATE [UNIQUE] INDEX statement for
77
// an index. Mirrors buildIndexDef in pgadmin_compat.go so clients that
78
// compared the indexdef string against a known form don't regress.
79
func pgIndexesIndexDef(tableName string, idx *sql.Index) string {
5✔
80
        colNames := make([]string, 0, len(idx.Cols()))
5✔
81
        for _, c := range idx.Cols() {
10✔
82
                colNames = append(colNames, c.Name())
5✔
83
        }
5✔
84
        verb := "CREATE INDEX"
5✔
85
        if idx.IsUnique() {
10✔
86
                verb = "CREATE UNIQUE INDEX"
5✔
87
        }
5✔
88
        return fmt.Sprintf("%s ON %s (%s)", verb, tableName, strings.Join(colNames, ", "))
5✔
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc