Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
76452: util/tracing: eliminate allocation for WithParent(<empty>) r=andreimatei a=andreimatei This patch makes WithRemoteParent(SpanMeta{}) not allocate a useless no-op span creation option. WithRemoteParent(SpanMeta{}) is superflous, but the call can happen when the caller that doesn't know whether there's a parent or not. I don't think the case is very common, but the optimization is very natural. This patch makes the no-op option be a represented as `nil`, as opposed to a heap-allocated empty struct. BenchmarkSetupSpanForIncomingRPC is enhanced to cover more code paths. The delta in the "/no_parent" case captures the improvement here - one allocation saved per not-traced RPC when tracing is generally enabled. ``` name old time/op new time/op delta SetupSpanForIncomingRPC/traceInfo-32 434ns ± 2% 445ns ± 1% +2.68% (p=0.008 n=5+5) SetupSpanForIncomingRPC/grpcMeta-32 1.22µs ± 3% 1.23µs ± 2% ~ (p=1.000 n=5+5) SetupSpanForIncomingRPC/no_parent-32 439ns ± 2% 312ns ± 1% -28.90% (p=0.008 n=5+5) name old alloc/op new alloc/op delta SetupSpanForIncomingRPC/traceInfo-32 144B ± 0% 144B ± 0% ~ (all equal) SetupSpanForIncomingRPC/grpcMeta-32 544B ± 0% 544B ± 0% ~ (all equal) SetupSpanForIncomingRPC/no_parent-32 144B ± 0% 48B ± 0% -66.67% (p=0.008 n=5+5) name old allocs/op new allocs/op delta SetupSpanForIncomingRPC/traceInfo-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) SetupSpanForIncomingRPC/grpcMeta-32 4.00 ± 0% 4.00 ± 0% ~ (all equal) SetupSpanForIncomingRPC/no_parent-32 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ``` Release note: None 76563: rowenc: fix splitting lookup rows into family spans in some cases r=yuzefovich a=yuzefovich Previously, we could incorrectly calculate whether fetching a KV for `FamilyID==0` is needed. The zeroth KV is always present, and we rely on it to find NULL values in columns in other column families. Before this patch we could "optimize" the behavior to not fetch the zeroth column family with composite non-nullable columns when we need to lookup nullable column families (families that only contain nullable columns); as a result, the lookup could come back empty when those columns only have NULLs. Consider the following example: ``` CREATE TABLE t ( pk1 DECIMAL NOT NULL, pk2 INT8 NOT NULL, c1 INT8, c2 INT8, PRIMARY KEY (pk1, pk2), UNIQUE (pk2), FAMILY fam_c1 (c1), FAMILY fam_c2 (pk1, pk2, c2) ); INSERT INTO t (pk1, pk2, c1, c2) VALUES (1:::DECIMAL, 0:::INT8, 0:::INT8); ``` When the INSERT statement is evaluated, only a KV entry for `fam_c1` is actually put into the KV layer (because the value part of `fam_c2` - `c2` column - is NULL). Next, when evaluating a query `SELECT c2 FROM t WHERE pk2 = 0;`, we first will scan the secondary unique index to fetch `/1/0` primary key. Then, we'll do an index join against the primary key to fetch `c2`. Before this patch, we would perform a Get of `/t/pk/1/0/1/1` (essentially trying to read `c2` directly of `fam_c2` - `/1/1` suffix is the varlen encoding of family ID 1); however, there is no such entry, so we would mistakenly think that the row is absent and return no rows. The problem was that we incorrectly determined `fam_c2` to be non-nullable, so we assumed it to always have a KV entry if a row is present. We made that determination based on the fact that `pk1` column (which is non-nullable, indexed, and composite) must force the existence of that KV entry because we're using the primary index encoding. However, I think that reasoning is just bogus. Any column family should be considered non-nullable IFF it has a non-nullable non-indexed column, so this patch removes all the business about non-nullable, indexed, composite columns. The zeroth column family is an exception that it is always non-nullable. Note that this patch makes us fetch more column families, so it should not be a correctness regression although it could be a performance regression if my reasoning is wrong. With this change in place we now correctly perform a scan of `/t/pk/1/{0-1}` span. Fixes: #76289. Release note (bug fix): Previously, CockroachDB could incorrectly not return a row from a table with multiple column families when that row contains a NULL value when a composite type (FLOAT, DECIMAL, COLLATED STRING, or an arrays of such a type) is included in the PRIMARY KEY. For the bug to occur composite column from the PRIMARY KEY must be included in any column family other than the first one. Co-authored-by: Andrei Matei <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]>
- Loading branch information