summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/sharded_index_projection_verbatim_persistence.js
blob: 042916e6f8061cf7bd8f1c671bda441aa00ad43f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * Tests that index projections are persisted in the originally submitted form, as opposed to
 * normalized form, in the catalog consistently across all shards. Exercises the fix for
 * SERVER-67446.
 * @tags: [
 *   # Uses index building in background
 *   requires_background_index,
 *   requires_fcv_63,
 * ]

 */
(function() {
"use strict";

load("jstests/libs/columnstore_util.js");  // For setUpServerForColumnStoreIndexTest.

const st = new ShardingTest({shards: 3, rs: {nodes: 1}});
const dbName = "test";
const collName = "user";
const ns = dbName + "." + collName;

assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
st.ensurePrimaryShard(dbName, st.shard0.shardName);

assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: "hashed"}}));

const kProjectionDoc = {
    "name": 0,
    "type": 0,
    "a.b": 0,
    "_id": 1
};

// Creates a wildcard index with a wildcardProjection that normalization would change and verifies
// the persisted projection doc on each shard matches the original, unnormalized version.
const kWildcardIndexName = "wc_index";
st.s.getCollection(ns).createIndex({"$**": 1},
                                   {name: kWildcardIndexName, wildcardProjection: kProjectionDoc});
let shardCatalogs =
    st.s.getCollection(ns)
        .aggregate([
            {$listCatalog: {}},
            {$unwind: "$md.indexes"},
            {$match: {"md.indexes.spec.name": kWildcardIndexName}},
            {$project: {shard: 1, wildcardProjection: "$md.indexes.spec.wildcardProjection"}}
        ])
        .toArray();
assert.eq(shardCatalogs.length, 3, shardCatalogs);
for (const catEntry of shardCatalogs) {
    assert.eq(catEntry.wildcardProjection, kProjectionDoc, shardCatalogs);
}

if (setUpServerForColumnStoreIndexTest(st.s.getDB(dbName))) {
    // Creates a columnstore index with a columnstoreProjection that normalization would change
    // and verifies the persisted projection doc on each shard matches the original,
    // unnormalized version.
    const kColumnstoreIndexName = "cs_index";
    st.s.getCollection(ns).createIndex(
        {"$**": "columnstore"},
        {name: kColumnstoreIndexName, columnstoreProjection: kProjectionDoc});
    shardCatalogs =
        st.s.getCollection(ns)
            .aggregate([
                {$listCatalog: {}},
                {$unwind: "$md.indexes"},
                {$match: {"md.indexes.spec.name": kColumnstoreIndexName}},
                {
                    $project:
                        {shard: 1, columnstoreProjection: "$md.indexes.spec.columnstoreProjection"}
                }
            ])
            .toArray();
    assert.eq(shardCatalogs.length, 3, shardCatalogs);
    for (const catEntry of shardCatalogs) {
        assert.eq(catEntry.columnstoreProjection, kProjectionDoc, shardCatalogs);
    }
}
st.stop();
})();