Skip to content

Commit 663064f

Browse files
authored
Make all queries to system.local use WHERE clause (#436)
Full scan requests slower even when only one record there is
1 parent 1e0eae9 commit 663064f

22 files changed

+75
-72
lines changed

examples/src/main/java/com/datastax/oss/driver/examples/astra/AstraReadCassandraVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static void main(String[] args) {
6464

6565
// We use execute to send a query to Cassandra. This returns a ResultSet, which
6666
// is essentially a collection of Row objects.
67-
ResultSet rs = session.execute("select release_version from system.local");
67+
ResultSet rs = session.execute("select release_version from system.local WHERE key='local'");
6868
// Extract the first row (which is the only one in this case).
6969
Row row = rs.one();
7070

examples/src/main/java/com/datastax/oss/driver/examples/basic/ReadCassandraVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void main(String[] args) {
4545
try (CqlSession session = CqlSession.builder().build()) {
4646
// We use execute to send a query to Cassandra. This returns a ResultSet, which
4747
// is essentially a collection of Row objects.
48-
ResultSet rs = session.execute("select release_version from system.local");
48+
ResultSet rs = session.execute("select release_version from system.local where key='local'");
4949
// Extract the first row (which is the only one in this case).
5050
Row row = rs.one();
5151

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseGssApiAuthProviderAlternateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static Object[][] saslSystemProperties() {
7474
"keyTab",
7575
ads.getUserKeytab().getAbsolutePath()))
7676
.build())) {
77-
Row row = session.execute("select * from system.local").one();
77+
Row row = session.execute("select * from system.local where key='local'").one();
7878
assertThat(row).isNotNull();
7979
} finally {
8080
System.clearProperty(saslSystemProperty);
@@ -104,7 +104,7 @@ public void should_authenticate_using_kerberos_with_keytab_and_alternate_service
104104
"keyTab",
105105
ads.getUserKeytab().getAbsolutePath()))
106106
.build())) {
107-
Row row = session.execute("select * from system.local").one();
107+
Row row = session.execute("select * from system.local where key='local'").one();
108108
assertThat(row).isNotNull();
109109
}
110110
}

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseGssApiAuthProviderIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class DseGssApiAuthProviderIT {
5050
@Test
5151
public void should_authenticate_using_kerberos_with_keytab() {
5252
try (CqlSession session = ads.newKeyTabSession()) {
53-
ResultSet set = session.execute("select * from system.local");
53+
ResultSet set = session.execute("select * from system.local where key='local'");
5454
assertThat(set).isNotNull();
5555
}
5656
}
@@ -67,7 +67,7 @@ public void should_authenticate_using_kerberos_with_ticket() throws Exception {
6767
Assume.assumeTrue(isUnix);
6868
acquireTicket(ads.getUserPrincipal(), ads.getUserKeytab(), ads.getAdsServer());
6969
try (CqlSession session = ads.newTicketSession()) {
70-
ResultSet set = session.execute("select * from system.local");
70+
ResultSet set = session.execute("select * from system.local where key='local'");
7171
assertThat(set).isNotNull();
7272
} finally {
7373
destroyTicket(ads);
@@ -133,7 +133,7 @@ public void should_authenticate_using_kerberos_with_keytab_programmatically() {
133133
.withAuthProvider(new ProgrammaticDseGssApiAuthProvider(builder.build()))
134134
.build()) {
135135

136-
ResultSet set = session.execute("select * from system.local");
136+
ResultSet set = session.execute("select * from system.local where key='local'");
137137
assertThat(set).isNotNull();
138138
}
139139
}

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DsePlainTextAuthProviderIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void should_connect_dse_plaintext_auth() {
7373
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, "cassandra")
7474
.withClass(DefaultDriverOption.AUTH_PROVIDER_CLASS, PlainTextAuthProvider.class)
7575
.build())) {
76-
session.execute("select * from system.local");
76+
session.execute("select * from system.local where key='local'");
7777
}
7878
}
7979

@@ -84,7 +84,7 @@ public void should_connect_dse_plaintext_auth_programmatically() {
8484
.addContactEndPoints(ccm.getContactPoints())
8585
.withAuthCredentials("cassandra", "cassandra")
8686
.build()) {
87-
session.execute("select * from system.local");
87+
session.execute("select * from system.local where key='local'");
8888
}
8989
}
9090

integration-tests/src/test/java/com/datastax/dse/driver/api/core/auth/DseProxyAuthenticationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void should_allow_plain_text_authorized_user_to_login_as_programmatically
114114
.addContactEndPoints(ads.ccm.getContactPoints())
115115
.withAuthCredentials("ben", "fakePasswordForBen", "alice")
116116
.build()) {
117-
session.execute("select * from system.local");
117+
session.execute("select * from system.local where key='local'");
118118
}
119119
}
120120

integration-tests/src/test/java/com/datastax/oss/driver/api/core/cloud/CloudIT.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void should_connect_to_proxy_using_path() {
8080
.withAuthCredentials("cassandra", "cassandra")
8181
.withCloudSecureConnectBundle(bundle)
8282
.build()) {
83-
set = session.execute("select * from system.local");
83+
set = session.execute("select * from system.local where key='local'");
8484
}
8585
assertThat(set).isNotNull();
8686
}
@@ -96,7 +96,7 @@ public void should_connect_and_log_info_that_config_json_with_username_password_
9696
.withAuthCredentials("cassandra", "cassandra")
9797
.withCloudSecureConnectBundle(bundle)
9898
.build()) {
99-
set = session.execute("select * from system.local");
99+
set = session.execute("select * from system.local where key='local'");
100100
verify(logger.appender, timeout(500).atLeast(1))
101101
.doAppend(logger.loggingEventCaptor.capture());
102102
assertThat(
@@ -135,7 +135,7 @@ public void should_connect_to_proxy_without_credentials() {
135135
.withCloudSecureConnectBundle(bundle)
136136
.withAuthCredentials("cassandra", "cassandra")
137137
.build()) {
138-
set = session.execute("select * from system.local");
138+
set = session.execute("select * from system.local where key='local'");
139139
}
140140
assertThat(set).isNotNull();
141141
}
@@ -149,7 +149,7 @@ public void should_connect_to_proxy_using_non_normalized_path() {
149149
.withAuthCredentials("cassandra", "cassandra")
150150
.withCloudSecureConnectBundle(bundle)
151151
.build()) {
152-
set = session.execute("select * from system.local");
152+
set = session.execute("select * from system.local where key='local'");
153153
}
154154
assertThat(set).isNotNull();
155155
}
@@ -163,7 +163,7 @@ public void should_connect_to_proxy_using_input_stream() throws IOException {
163163
.withAuthCredentials("cassandra", "cassandra")
164164
.withCloudSecureConnectBundle(bundle)
165165
.build()) {
166-
set = session.execute("select * from system.local");
166+
set = session.execute("select * from system.local where key='local'");
167167
}
168168
assertThat(set).isNotNull();
169169
}
@@ -191,7 +191,7 @@ public void should_connect_to_proxy_using_URL() throws IOException {
191191
.build()) {
192192

193193
// then
194-
set = session.execute("select * from system.local");
194+
set = session.execute("select * from system.local where key='local'");
195195
}
196196
assertThat(set).isNotNull();
197197
}
@@ -213,7 +213,7 @@ public void should_connect_to_proxy_using_absolute_path_provided_in_the_session_
213213
.build()) {
214214

215215
// then
216-
set = session.execute("select * from system.local");
216+
set = session.execute("select * from system.local where key='local'");
217217
}
218218
assertThat(set).isNotNull();
219219
}
@@ -236,7 +236,7 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
236236
.build()) {
237237

238238
// then
239-
set = session.execute("select * from system.local");
239+
set = session.execute("select * from system.local where key='local'");
240240
}
241241
assertThat(set).isNotNull();
242242
}
@@ -259,7 +259,7 @@ public void should_connect_to_proxy_using_non_normalized_path_provided_in_the_se
259259
.build()) {
260260

261261
// then
262-
set = session.execute("select * from system.local");
262+
set = session.execute("select * from system.local where key='local'");
263263
}
264264
assertThat(set).isNotNull();
265265
}
@@ -290,7 +290,7 @@ public void should_connect_to_proxy_using_url_with_http_protocol_provided_in_the
290290
.build()) {
291291

292292
// then
293-
set = session.execute("select * from system.local");
293+
set = session.execute("select * from system.local where key='local'");
294294
}
295295
assertThat(set).isNotNull();
296296
}
@@ -311,7 +311,7 @@ public void should_connect_to_proxy_using_url_with_http_protocol_provided_in_the
311311
.build(); ) {
312312

313313
// when
314-
ResultSet set = session.execute("select * from system.local");
314+
ResultSet set = session.execute("select * from system.local where key='local'");
315315
// then
316316
assertThat(set).isNotNull();
317317
verify(logger.appender, timeout(500).atLeast(1))
@@ -348,7 +348,7 @@ public void should_connect_and_log_info_when_contact_points_and_secure_bundle_us
348348
.build(); ) {
349349

350350
// when
351-
ResultSet set = session.execute("select * from system.local");
351+
ResultSet set = session.execute("select * from system.local where key='local'");
352352
// then
353353
assertThat(set).isNotNull();
354354
verify(logger.appender, timeout(500).atLeast(1))
@@ -379,7 +379,7 @@ public void should_connect_and_log_info_when_ssl_context_and_secure_bundle_used_
379379
.withSslContext(SSLContext.getInstance("SSL"))
380380
.build()) {
381381
// when
382-
ResultSet set = session.execute("select * from system.local");
382+
ResultSet set = session.execute("select * from system.local where key='local'");
383383
// then
384384
assertThat(set).isNotNull();
385385
verify(logger.appender, timeout(500).atLeast(1))
@@ -415,7 +415,7 @@ public void should_error_when_ssl_context_and_secure_bundle_used_config()
415415
.withAuthCredentials("cassandra", "cassandra")
416416
.build()) {
417417
// when
418-
ResultSet set = session.execute("select * from system.local");
418+
ResultSet set = session.execute("select * from system.local where key='local'");
419419
// then
420420
assertThat(set).isNotNull();
421421
verify(logger.appender, timeout(500).atLeast(1))
@@ -451,7 +451,7 @@ public void should_error_when_ssl_context_and_secure_bundle_used_config()
451451
.build(); ) {
452452

453453
// when
454-
ResultSet set = session.execute("select * from system.local");
454+
ResultSet set = session.execute("select * from system.local where key='local'");
455455
// then
456456
assertThat(set).isNotNull();
457457
verify(logger.appender, timeout(500).atLeast(1))
@@ -482,7 +482,7 @@ public void should_connect_and_log_info_when_local_data_center_and_secure_bundle
482482
.build(); ) {
483483

484484
// when
485-
ResultSet set = session.execute("select * from system.local");
485+
ResultSet set = session.execute("select * from system.local where key='local'");
486486
// then
487487
assertThat(set).isNotNull();
488488
verify(logger.appender, timeout(500).atLeast(1))

integration-tests/src/test/java/com/datastax/oss/driver/core/PoolBalancingIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void reschedule(AsyncResultSet asyncResultSet, Throwable throwable) {
9999
}
100100
SESSION_RULE
101101
.session()
102-
.executeAsync("SELECT release_version FROM system.local")
102+
.executeAsync("SELECT release_version FROM system.local WHERE key='local'")
103103
.whenComplete(this::reschedule);
104104
}
105105
}

integration-tests/src/test/java/com/datastax/oss/driver/core/ProtocolVersionInitialNegotiationIT.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ProtocolVersionInitialNegotiationIT {
6363
public void should_downgrade_to_v3() {
6464
try (CqlSession session = SessionUtils.newSession(ccm)) {
6565
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
66-
session.execute("select * from system.local");
66+
session.execute("select * from system.local where key='local'");
6767
}
6868
}
6969

@@ -81,7 +81,7 @@ public void should_downgrade_to_v3() {
8181
public void should_downgrade_to_v4() {
8282
try (CqlSession session = SessionUtils.newSession(ccm)) {
8383
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
84-
session.execute("select * from system.local");
84+
session.execute("select * from system.local where key='local'");
8585
}
8686
}
8787

@@ -96,7 +96,7 @@ public void should_downgrade_to_v4() {
9696
public void should_downgrade_to_v5_oss() {
9797
try (CqlSession session = SessionUtils.newSession(ccm)) {
9898
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(5);
99-
session.execute("select * from system.local");
99+
session.execute("select * from system.local where key='local'");
100100
}
101101
}
102102

@@ -109,7 +109,7 @@ public void should_downgrade_to_v5_oss() {
109109
public void should_downgrade_to_dse_v1() {
110110
try (CqlSession session = SessionUtils.newSession(ccm)) {
111111
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V1);
112-
session.execute("select * from system.local");
112+
session.execute("select * from system.local where key='local'");
113113
}
114114
}
115115

@@ -222,7 +222,7 @@ public void should_fail_if_provided_dse_v2_is_not_supported() {
222222
public void should_not_downgrade_if_server_supports_latest_version() {
223223
try (CqlSession session = SessionUtils.newSession(ccm)) {
224224
assertThat(session.getContext().getProtocolVersion()).isEqualTo(ProtocolVersion.V5);
225-
session.execute("select * from system.local");
225+
session.execute("select * from system.local where key='local'");
226226
}
227227
}
228228

@@ -235,7 +235,7 @@ public void should_not_downgrade_if_server_supports_latest_version() {
235235
public void should_not_downgrade_if_server_supports_latest_version_dse() {
236236
try (CqlSession session = SessionUtils.newSession(ccm)) {
237237
assertThat(session.getContext().getProtocolVersion()).isEqualTo(ProtocolVersion.DSE_V2);
238-
session.execute("select * from system.local");
238+
session.execute("select * from system.local where key='local'");
239239
}
240240
}
241241

@@ -255,7 +255,7 @@ public void should_use_explicitly_provided_v3() {
255255
.build();
256256
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
257257
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
258-
session.execute("select * from system.local");
258+
session.execute("select * from system.local where key='local'");
259259
}
260260
}
261261

@@ -275,7 +275,7 @@ public void should_use_explicitly_provided_v4() {
275275
.build();
276276
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
277277
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
278-
session.execute("select * from system.local");
278+
session.execute("select * from system.local where key='local'");
279279
}
280280
}
281281

@@ -298,7 +298,7 @@ public void should_use_explicitly_provided_v5() {
298298
.build();
299299
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
300300
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(5);
301-
session.execute("select * from system.local");
301+
session.execute("select * from system.local where key='local'");
302302
}
303303
}
304304

@@ -314,7 +314,7 @@ public void should_use_explicitly_provided_dse_v1() {
314314
.build();
315315
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
316316
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V1);
317-
session.execute("select * from system.local");
317+
session.execute("select * from system.local where key='local'");
318318
}
319319
}
320320

@@ -330,7 +330,7 @@ public void should_use_explicitly_provided_dse_v2() {
330330
.build();
331331
try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
332332
assertThat(session.getContext().getProtocolVersion()).isEqualTo(DseProtocolVersion.DSE_V2);
333-
session.execute("select * from system.local");
333+
session.execute("select * from system.local where key='local'");
334334
}
335335
}
336336
}

0 commit comments

Comments
 (0)