2 Star 2 Fork 1

cockroachdb/cockroach

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
build
c-deps
cloud
docs
githooks
monitoring
pkg
acceptance
base
build
ccl
cli
cmd
config
gossip
internal
keys
kv
roachpb
rpc
security
server
settings
sql
distsqlplan
distsqlrun
ir
jobs
logictest
mon
parser
pgbench
pgwire
privilege
sqlbase
cancel_checker.go
constants.go
default_exprs.go
encoded_datum.go
encoded_datum.pb.go
encoded_datum.proto
encoded_datum_test.go
errors.go
expr_filter.go
fk.go
formatversion_string.go
keys.go
keys_test.go
kvfetcher.go
main_test.go
metadata.go
ordering.go
privilege.go
privilege.pb.go
privilege.proto
privilege_test.go
result_columns.go
result_columns_test.go
row_container.go
row_container_test.go
rowfetcher.go
rowwriter.go
sort.go
structured.go
structured.pb.go
structured.proto
structured_test.go
system.go
table.go
table_test.go
testutils.go
time_zone_util.go
sqlutil
tracedata
alter_table.go
ambiguous_commit_test.go
analyze.go
analyze_test.go
app_stats.go
as_of_test.go
authorization.go
backfill.go
bank_test.go
bench_test.go
builtin_mem_usage_test.go
check.go
config.go
config_test.go
copy.go
copy_in_test.go
copy_test.go
crdb_internal.go
create.go
create_test.go
data_source.go
database.go
database_test.go
delayed.go
delete.go
descriptor.go
descriptor_mutation_test.go
discard.go
distinct.go
distsql_physical_planner.go
distsql_physical_planner_test.go
distsql_running.go
doc.go
drop.go
drop_test.go
event_log.go
executor.go
executor_statement_metrics.go
executor_test.go
expand_plan.go
explain.go
explain_plan.go
expr_filter.go
expr_filter_test.go
filter.go
filter_opt.go
generator.go
grant.go
group.go
group_test.go
helpers_test.go
impure_builtin_test.go
index_join.go
index_selection.go
index_selection_test.go
indexbackfiller_test.go
information_schema.go
insert.go
internal.go
join.go
join_predicate.go
kv_test.go
lease.go
lease_internal_test.go
lease_test.go
limit.go
limit_opt.go
main_test.go
mem_metrics.go
metric_test.go
metric_util_test.go
monotonic_insert_test.go
needed_columns.go
optimize.go
ordering.go
ordering_test.go
ordinality.go
parallel_stmts.go
parallel_stmts_test.go
pg_catalog.go
pgbench_test.go
pgwire_internal_test.go
plan.go
plan_columns.go
plan_ordering.go
plan_spans.go
planhook.go
planhook_test.go
planner.go
planner_test.go
prepare.go
rename.go
rename_test.go
render.go
results_writer.go
results_writer_test.go
returning.go
row_buffer.go
rsg_test.go
run_control.go
run_control_test.go
scan.go
scan_test.go
schema_changer.go
schema_changer_test.go
select_name_resolution.go
select_name_resolution_test.go
session.go
session_mem_usage.go
session_test.go
set.go
show.go
show_create.go
show_fingerprints.go
show_fingerprints_test.go
show_ranges.go
show_test.go
sort.go
sort_test.go
split_at.go
split_at_test.go
split_test.go
subquery.go
subquery_test.go
system_table_test.go
table.go
table_ref_test.go
table_split_test.go
table_test.go
tablewriter.go
targets.go
trace.go
trace_test.go
truncate.go
txn.go
txn_restart_test.go
txnstateenum_string.go
unary.go
union.go
update.go
upsert.go
upsert_test.go
user.go
values.go
values_test.go
vars.go
verify.go
views.go
virtual_schema.go
walk.go
window.go
zero.go
sqlmigrations
storage
testutils
ts
ui
util
Makefile
scripts
.codacy.yml
.editorconfig
.gitattributes
.gitignore
.gitmodules
.go-version
.mailmap
APL.txt
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
STYLE.md
main.go
克隆/下载
ordering.go 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2016 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package sqlbase
import (
"github.com/cockroachdb/cockroach/pkg/sql/parser"
"github.com/cockroachdb/cockroach/pkg/util/encoding"
)
// ColumnOrderInfo describes a column (as an index) and a desired order
// direction.
type ColumnOrderInfo struct {
ColIdx int
Direction encoding.Direction
}
// ColumnOrdering is used to describe a desired column ordering. For example,
// []ColumnOrderInfo{ {3, true}, {1, false} }
// represents an ordering first by column 3 (descending), then by column 1 (ascending).
type ColumnOrdering []ColumnOrderInfo
// IsPrefixOf returns true if the receiver ordering matches a prefix of the
// given ordering. In this case, rows with an order conforming to b
// automatically conform to a.
func (a ColumnOrdering) IsPrefixOf(b ColumnOrdering) bool {
if len(a) > len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// CompareDatums compares two datum rows according to a column ordering. Returns:
// - 0 if lhs and rhs are equal on the ordering columns;
// - less than 0 if lhs comes first;
// - greater than 0 if rhs comes first.
func CompareDatums(
ordering ColumnOrdering, evalCtx *parser.EvalContext, lhs, rhs parser.Datums,
) int {
for _, c := range ordering {
// TODO(pmattis): This is assuming that the datum types are compatible. I'm
// not sure this always holds as `CASE` expressions can return different
// types for a column for different rows. Investigate how other RDBMs
// handle this.
if cmp := lhs[c.ColIdx].Compare(evalCtx, rhs[c.ColIdx]); cmp != 0 {
if c.Direction == encoding.Descending {
cmp = -cmp
}
return cmp
}
}
return 0
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_cockroachdb/cockroach.git
git@gitee.com:mirrors_cockroachdb/cockroach.git
mirrors_cockroachdb
cockroach
cockroach
v1.1.5

搜索帮助