Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow order by on non-indexed fields #1961

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ COPY --from=build /src/immudb /usr/sbin/immudb
COPY --from=build /src/immuadmin /usr/local/bin/immuadmin
COPY --from=build --chown="$IMMU_UID:$IMMU_GID" /empty "$IMMUDB_HOME"
COPY --from=build --chown="$IMMU_UID:$IMMU_GID" /empty "$IMMUDB_DIR"
COPY --from=build --chown="$IMMU_UID:$IMMU_GID" /empty /tmp
COPY --from=build "/etc/ssl/certs/ca-certificates.crt" "/etc/ssl/certs/ca-certificates.crt"

EXPOSE 3322
Expand Down
32 changes: 30 additions & 2 deletions embedded/sql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ var ErrNotNullableColumnCannotBeNull = errors.New("not nullable column can not b
var ErrNewColumnMustBeNullable = errors.New("new column must be nullable")
var ErrIndexAlreadyExists = errors.New("index already exists")
var ErrMaxNumberOfColumnsInIndexExceeded = errors.New("number of columns in multi-column index exceeded")
var ErrNoAvailableIndex = errors.New("no available index")
var ErrIndexNotFound = errors.New("index not found")
var ErrInvalidNumberOfValues = errors.New("invalid number of values provided")
var ErrInvalidValue = errors.New("invalid value provided")
var ErrInferredMultipleTypes = errors.New("inferred multiple types")
var ErrExpectingDQLStmt = errors.New("illegal statement. DQL statement expected")
var ErrLimitedOrderBy = errors.New("order is limit to one indexed column")
var ErrLimitedOrderBy = errors.New("order by is limited to one column")
var ErrLimitedGroupBy = errors.New("group by requires ordering by the grouping column")
var ErrIllegalMappedKey = errors.New("error illegal mapped key")
var ErrCorruptedData = store.ErrCorruptedData
Expand Down Expand Up @@ -104,6 +103,7 @@ type Engine struct {

prefix []byte
distinctLimit int
sortBufferSize int
autocommit bool
lazyIndexConstraintValidation bool

Expand Down Expand Up @@ -144,6 +144,7 @@ func NewEngine(st *store.ImmuStore, opts *Options) (*Engine, error) {
store: st,
prefix: make([]byte, len(opts.prefix)),
distinctLimit: opts.distinctLimit,
sortBufferSize: opts.sortBufferSize,
autocommit: opts.autocommit,
lazyIndexConstraintValidation: opts.lazyIndexConstraintValidation,
multidbHandler: opts.multidbHandler,
Expand Down Expand Up @@ -506,6 +507,33 @@ func (e *Engine) execPreparedStmts(ctx context.Context, tx *SQLTx, stmts []SQLSt
return currTx, committedTxs, stmts[execStmts:], nil
}

func (e *Engine) queryAll(ctx context.Context, tx *SQLTx, sql string, params map[string]interface{}) ([]*Row, error) {
reader, err := e.Query(ctx, tx, sql, params)
if err != nil {
return nil, err
}
defer reader.Close()

return readAllRows(ctx, reader)
}

func readAllRows(ctx context.Context, reader RowReader) ([]*Row, error) {
rows := make([]*Row, 0, 100)
for {
row, err := reader.Read(ctx)
if err == ErrNoMoreRows {
break
}

if err != nil {
return nil, err
}

rows = append(rows, row)
}
return rows, nil
}

func (e *Engine) Query(ctx context.Context, tx *SQLTx, sql string, params map[string]interface{}) (RowReader, error) {
stmts, err := Parse(strings.NewReader(sql))
if err != nil {
Expand Down
Loading
Loading