Validate that channels queries (channels, starChannel) are covering
(t *testing.T)
| 127 | |
| 128 | // Validate that channels queries (channels, starChannel) are covering |
| 129 | func TestCoveringQueries(t *testing.T) { |
| 130 | if base.TestsDisableGSI() { |
| 131 | t.Skip("This test is Couchbase Server and UseViews=false only") |
| 132 | } |
| 133 | |
| 134 | db, ctx := setupTestDB(t) |
| 135 | defer db.Close(ctx) |
| 136 | |
| 137 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 138 | n1QLStore, ok := base.AsN1QLStore(collection.dataStore) |
| 139 | if !ok { |
| 140 | t.Errorf("Unable to get n1QLStore for testBucket") |
| 141 | } |
| 142 | |
| 143 | // channels |
| 144 | channelsStatement, params := collection.buildChannelsQuery("ABC", 0, 10, 100, false) |
| 145 | plan, explainErr := n1QLStore.ExplainQuery(ctx, channelsStatement, params) |
| 146 | assert.NoError(t, explainErr, "Error generating explain for channels query") |
| 147 | covered := IsCovered(plan) |
| 148 | planJSON, err := base.JSONMarshal(plan) |
| 149 | assert.NoError(t, err) |
| 150 | assert.True(t, covered, "Channel query isn't covered by index: %s", planJSON) |
| 151 | |
| 152 | // star channel |
| 153 | channelStarStatement, params := collection.buildChannelsQuery("*", 0, 10, 100, false) |
| 154 | plan, explainErr = n1QLStore.ExplainQuery(ctx, channelStarStatement, params) |
| 155 | assert.NoError(t, explainErr, "Error generating explain for star channel query") |
| 156 | covered = IsCovered(plan) |
| 157 | planJSON, err = base.JSONMarshal(plan) |
| 158 | assert.NoError(t, err) |
| 159 | assert.True(t, covered, "Star channel query isn't covered by index: %s", planJSON) |
| 160 | |
| 161 | // Access and roleAccess currently aren't covering, because of the need to target the user property by name |
| 162 | // in the SELECT. |
| 163 | // Including here for ease-of-conversion when we get an indexing enhancement to support covered queries. |
| 164 | accessStatement := collection.buildAccessQuery("user1") |
| 165 | plan, explainErr = n1QLStore.ExplainQuery(ctx, accessStatement, nil) |
| 166 | assert.NoError(t, explainErr, "Error generating explain for access query") |
| 167 | covered = IsCovered(plan) |
| 168 | planJSON, err = base.JSONMarshal(plan) |
| 169 | assert.NoError(t, err) |
| 170 | require.False(t, covered, "Access query isn't covered by index: %s", planJSON) |
| 171 | |
| 172 | // roleAccess |
| 173 | roleAccessStatement := collection.buildRoleAccessQuery("user1") |
| 174 | plan, explainErr = n1QLStore.ExplainQuery(ctx, roleAccessStatement, nil) |
| 175 | assert.NoError(t, explainErr, "Error generating explain for roleAccess query") |
| 176 | covered = IsCovered(plan) |
| 177 | planJSON, err = base.JSONMarshal(plan) |
| 178 | assert.NoError(t, err) |
| 179 | require.False(t, covered, "RoleAccess query isn't covered by index: %s", planJSON) |
| 180 | |
| 181 | } |
| 182 | |
| 183 | func TestAllDocsQuery(t *testing.T) { |
| 184 |
nothing calls this directly
no test coverage detected