Skip to content

Commit

Permalink
Alow order by on non indexed fields
Browse files Browse the repository at this point in the history
Signed-off-by: Stefano Scafiti <[email protected]>
  • Loading branch information
ostafen committed Apr 26, 2024
1 parent e9e5c47 commit 68b32d5
Show file tree
Hide file tree
Showing 11 changed files with 1,086 additions and 180 deletions.
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

0 comments on commit 68b32d5

Please sign in to comment.