Skip to content

Commit 3db6c2c

Browse files
authored
Make any query to system.local use WHERE clause (#419)
Full scan queries are slower even if there is only one record.
1 parent f05e37f commit 3db6c2c

23 files changed

+53
-53
lines changed

examples/request_init_listener.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def __str__(self):
6868
# attach a listener to this session
6969
ra = RequestAnalyzer(session)
7070

71-
session.execute("SELECT release_version FROM system.local")
72-
session.execute("SELECT release_version FROM system.local")
71+
session.execute("SELECT release_version FROM system.local WHERE key='local'")
72+
session.execute("SELECT release_version FROM system.local WHERE key='local'")
7373

7474
print(ra)
7575
# 2 requests (0 errors)

tests/integration/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def get_server_versions():
8787

8888
c = TestCluster()
8989
s = c.connect()
90-
row = s.execute('SELECT cql_version, release_version FROM system.local').one()
90+
row = s.execute("SELECT cql_version, release_version FROM system.local WHERE key='local'").one()
9191

9292
cass_version = _tuple_version(row.release_version)
9393
cql_version = _tuple_version(row.cql_version)

tests/integration/advanced/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def connect_and_query(self, auth_provider, query=None):
157157
os.environ['KRB5_CONFIG'] = self.krb_conf
158158
self.cluster = TestCluster(auth_provider=auth_provider)
159159
self.session = self.cluster.connect()
160-
query = query if query else "SELECT * FROM system.local"
160+
query = query if query else "SELECT * FROM system.local WHERE key='local'"
161161
statement = SimpleStatement(query)
162162
rs = self.session.execute(statement)
163163
return rs
@@ -529,4 +529,4 @@ def test_connection_with_transitional_mode(self):
529529
@expected_result connect and query should be allowed
530530
"""
531531
auth_provider = TransitionalModePlainTextAuthProvider()
532-
self.assertIsNotNone(self.connect_and_query(auth_provider, query="SELECT * from system.local"))
532+
self.assertIsNotNone(self.connect_and_query(auth_provider, query="SELECT * from system.local WHERE key='local'"))

tests/integration/advanced/test_unixsocketendpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ def tearDownClass(cls):
7171

7272
def test_unix_socket_connection(self):
7373
s = self.cluster.connect()
74-
s.execute('select * from system.local')
74+
s.execute("select * from system.local where key='local'")

tests/integration/cloud/test_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_match_system_local(self):
6262

6363
self.assertEqual(len(self.hosts_up()), 3)
6464
for host in self.cluster.metadata.all_hosts():
65-
row = self.session.execute('SELECT * FROM system.local', host=host).one()
65+
row = self.session.execute("SELECT * FROM system.local WHERE key='local'", host=host).one()
6666
self.assertEqual(row.host_id, host.host_id)
6767
self.assertEqual(row.rpc_address, host.broadcast_rpc_address)
6868

tests/integration/long/test_consistency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def test_pool_with_host_down(self):
354354
# Attempt a query against that node. It should complete
355355
cluster2 = TestCluster(contact_points=all_contact_points)
356356
session2 = cluster2.connect()
357-
session2.execute("SELECT * FROM system.local")
357+
session2.execute("SELECT * FROM system.local WHERE key='local'")
358358
finally:
359359
cluster2.shutdown()
360360
start(node_to_stop)

tests/integration/long/test_ipv6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class IPV6ConnectionTest(object):
8080
def test_connect(self):
8181
cluster = TestCluster(connection_class=self.connection_class, contact_points=['::1'], connect_timeout=10)
8282
session = cluster.connect()
83-
future = session.execute_async("SELECT * FROM system.local")
83+
future = session.execute_async("SELECT * FROM system.local WHERE key='local'")
8484
future.result()
8585
self.assertEqual(future._current_host.address, '::1')
8686
cluster.shutdown()

tests/integration/long/test_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_can_connect_with_ssl_long_running(self):
193193
# attempt a few simple commands.
194194

195195
for i in range(8):
196-
rs = session.execute("SELECT * FROM system.local")
196+
rs = session.execute("SELECT * FROM system.local WHERE key='local'")
197197
time.sleep(10)
198198

199199
cluster.shutdown()

tests/integration/simulacron/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,14 @@ def test_driver_recovers_nework_isolation(self):
464464
for host in cluster.metadata.all_hosts():
465465
self.assertIn(host, listener.hosts_marked_down)
466466

467-
self.assertRaises(NoHostAvailable, session.execute, "SELECT * from system.local")
467+
self.assertRaises(NoHostAvailable, session.execute, "SELECT * from system.local WHERE key='local'")
468468

469469
clear_queries()
470470
prime_request(AcceptConnections())
471471

472472
time.sleep(idle_heartbeat_timeout + idle_heartbeat_interval + 2)
473473

474-
self.assertIsNotNone(session.execute("SELECT * from system.local"))
474+
self.assertIsNotNone(session.execute("SELECT * from system.local WHERE key='local'"))
475475

476476
def test_max_in_flight(self):
477477
""" Verify we don't exceed max_in_flight when borrowing connections or sending heartbeats """

tests/integration/simulacron/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def prime_server_versions(self):
125125
if DSE_VERSION:
126126
system_local_row["dse_version"] = DSE_VERSION.base_version
127127
column_types = {"cql_version": "ascii", "release_version": "ascii"}
128-
system_local = PrimeQuery("SELECT cql_version, release_version FROM system.local",
128+
system_local = PrimeQuery("SELECT cql_version, release_version FROM system.local WHERE key='local'",
129129
rows=[system_local_row],
130130
column_types=column_types)
131131

tests/integration/standard/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_auth_connect(self):
105105
cluster = self.cluster_as(user, passwd)
106106
session = cluster.connect(wait_for_all_pools=True)
107107
try:
108-
self.assertTrue(session.execute('SELECT release_version FROM system.local'))
108+
self.assertTrue(session.execute("SELECT release_version FROM system.local WHERE key='local'"))
109109
assert_quiescent_pool_state(self, cluster, wait=1)
110110
for pool in session.get_pools():
111111
connection, _ = pool.borrow_connection(timeout=0)

tests/integration/standard/test_cluster.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,15 @@ def test_trace(self):
589589
cluster = TestCluster()
590590
session = cluster.connect()
591591

592-
result = session.execute( "SELECT * FROM system.local", trace=True)
592+
result = session.execute( "SELECT * FROM system.local WHERE key='local'", trace=True)
593593
self._check_trace(result.get_query_trace())
594594

595-
query = "SELECT * FROM system.local"
595+
query = "SELECT * FROM system.local WHERE key='local'"
596596
statement = SimpleStatement(query)
597597
result = session.execute(statement, trace=True)
598598
self._check_trace(result.get_query_trace())
599599

600-
query = "SELECT * FROM system.local"
600+
query = "SELECT * FROM system.local WHERE key='local'"
601601
statement = SimpleStatement(query)
602602
result = session.execute(statement)
603603
self.assertIsNone(result.get_query_trace())
@@ -612,7 +612,7 @@ def test_trace(self):
612612
future.result()
613613
self.assertIsNone(future.get_query_trace())
614614

615-
prepared = session.prepare("SELECT * FROM system.local")
615+
prepared = session.prepare("SELECT * FROM system.local WHERE key='local'")
616616
future = session.execute_async(prepared, parameters=(), trace=True)
617617
future.result()
618618
self._check_trace(future.get_query_trace())
@@ -636,7 +636,7 @@ def test_trace_unavailable(self):
636636
self.addCleanup(cluster.shutdown)
637637
session = cluster.connect()
638638

639-
query = "SELECT * FROM system.local"
639+
query = "SELECT * FROM system.local WHERE key='local'"
640640
statement = SimpleStatement(query)
641641

642642
max_retry_count = 10
@@ -686,7 +686,7 @@ def test_string_coverage(self):
686686
cluster = TestCluster()
687687
session = cluster.connect()
688688

689-
query = "SELECT * FROM system.local"
689+
query = "SELECT * FROM system.local WHERE key='local'"
690690
statement = SimpleStatement(query)
691691
future = session.execute_async(statement)
692692

@@ -742,7 +742,7 @@ def _warning_are_issued_when_auth(self, auth_provider):
742742
with MockLoggingHandler().set_module_name(connection.__name__) as mock_handler:
743743
with TestCluster(auth_provider=auth_provider) as cluster:
744744
session = cluster.connect()
745-
self.assertIsNotNone(session.execute("SELECT * from system.local"))
745+
self.assertIsNotNone(session.execute("SELECT * from system.local WHERE key='local'"))
746746

747747
# Three conenctions to nodes plus the control connection
748748
auth_warning = mock_handler.get_message_count('warning', "An authentication challenge was not sent")
@@ -786,7 +786,7 @@ def test_idle_heartbeat(self):
786786
self.assertTrue(all(c.is_idle for c in connections))
787787

788788
# send messages on all connections
789-
statements_and_params = [("SELECT release_version FROM system.local", ())] * len(cluster.metadata.all_hosts())
789+
statements_and_params = [("SELECT release_version FROM system.local WHERE key='local'", ())] * len(cluster.metadata.all_hosts())
790790
results = execute_concurrent(session, statements_and_params)
791791
for success, result in results:
792792
self.assertTrue(success)
@@ -871,7 +871,7 @@ def test_profile_load_balancing(self):
871871
872872
@test_category config_profiles
873873
"""
874-
query = "select release_version from system.local"
874+
query = "select release_version from system.local where key='local'"
875875
node1 = ExecutionProfile(
876876
load_balancing_policy=HostFilterPolicy(
877877
RoundRobinPolicy(), lambda host: host.address == CASSANDRA_IP
@@ -942,7 +942,7 @@ def test_profile_lb_swap(self):
942942
943943
@test_category config_profiles
944944
"""
945-
query = "select release_version from system.local"
945+
query = "select release_version from system.local where key='local'"
946946
rr1 = ExecutionProfile(load_balancing_policy=RoundRobinPolicy())
947947
rr2 = ExecutionProfile(load_balancing_policy=RoundRobinPolicy())
948948
exec_profiles = {'rr1': rr1, 'rr2': rr2}
@@ -971,7 +971,7 @@ def test_ta_lbp(self):
971971
972972
@test_category config_profiles
973973
"""
974-
query = "select release_version from system.local"
974+
query = "select release_version from system.local where key='local'"
975975
ta1 = ExecutionProfile()
976976
with TestCluster() as cluster:
977977
session = cluster.connect()
@@ -991,7 +991,7 @@ def test_clone_shared_lbp(self):
991991
992992
@test_category config_profiles
993993
"""
994-
query = "select release_version from system.local"
994+
query = "select release_version from system.local where key='local'"
995995
rr1 = ExecutionProfile(load_balancing_policy=RoundRobinPolicy())
996996
exec_profiles = {'rr1': rr1}
997997
with TestCluster(execution_profiles=exec_profiles) as cluster:
@@ -1018,7 +1018,7 @@ def test_missing_exec_prof(self):
10181018
10191019
@test_category config_profiles
10201020
"""
1021-
query = "select release_version from system.local"
1021+
query = "select release_version from system.local where key='local'"
10221022
rr1 = ExecutionProfile(load_balancing_policy=RoundRobinPolicy())
10231023
rr2 = ExecutionProfile(load_balancing_policy=RoundRobinPolicy())
10241024
exec_profiles = {'rr1': rr1, 'rr2': rr2}

tests/integration/standard/test_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_in_flight_timeout(self):
8686
@test_category connection timeout
8787
"""
8888
futures = []
89-
query = '''SELECT * FROM system.local'''
89+
query = "SELECT * FROM system.local WHERE key='local'"
9090
for _ in range(100):
9191
futures.append(self.session.execute_async(query))
9292

@@ -151,7 +151,7 @@ def test_heart_beat_timeout(self):
151151
current_host = ""
152152
count = 0
153153
while current_host != host and count < 100:
154-
rs = self.session.execute_async("SELECT * FROM system.local", trace=False)
154+
rs = self.session.execute_async("SELECT * FROM system.local WHERE key='local'", trace=False)
155155
rs.result()
156156
current_host = str(rs._current_host)
157157
count += 1

tests/integration/standard/test_custom_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def test_connection_honor_cluster_port(self):
5353
wait_until(lambda: len(cluster.metadata.all_hosts()) == 3, 1, 5)
5454
for host in cluster.metadata.all_hosts():
5555
self.assertTrue(host.is_up)
56-
session.execute("select * from system.local", host=host)
56+
session.execute("select * from system.local where key='local'", host=host)

tests/integration/standard/test_custom_payload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_custom_query_basic(self):
5656
"""
5757

5858
# Create a simple query statement a
59-
query = "SELECT * FROM system.local"
59+
query = "SELECT * FROM system.local WHERE key='local'"
6060
statement = SimpleStatement(query)
6161
# Validate that various types of custom payloads are sent and received okay
6262
self.validate_various_custom_payloads(statement=statement)

tests/integration/standard/test_custom_protocol_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ def test_custom_raw_uuid_row_results(self):
6969
)
7070
session = cluster.connect(keyspace="custserdes")
7171

72-
result = session.execute("SELECT schema_version FROM system.local")
72+
result = session.execute("SELECT schema_version FROM system.local WHERE key='local'")
7373
uuid_type = result.one()[0]
7474
self.assertEqual(type(uuid_type), uuid.UUID)
7575

7676
# use our custom protocol handlder
7777
session.client_protocol_handler = CustomTestRawRowType
78-
result_set = session.execute("SELECT schema_version FROM system.local")
78+
result_set = session.execute("SELECT schema_version FROM system.local WHERE key='local'")
7979
raw_value = result_set.one()[0]
8080
self.assertTrue(isinstance(raw_value, bytes))
8181
self.assertEqual(len(raw_value), 16)
8282

8383
# Ensure that we get normal uuid back when we re-connect
8484
session.client_protocol_handler = ProtocolHandler
85-
result_set = session.execute("SELECT schema_version FROM system.local")
85+
result_set = session.execute("SELECT schema_version FROM system.local WHERE key='local'")
8686
uuid_type = result_set.one()[0]
8787
self.assertEqual(type(uuid_type), uuid.UUID)
8888
cluster.shutdown()

tests/integration/standard/test_ip_change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def new_address_found():
5252

5353
def new_node_connectable():
5454
LOGGER.info(self.cluster.shard_aware_stats())
55-
local_info = self.session.execute("SELECT * FROM system.local", execution_profile="new_node").one()
55+
local_info = self.session.execute("SELECT * FROM system.local WHERE key='local'", execution_profile="new_node").one()
5656
LOGGER.debug(local_info._asdict())
5757
assert local_info.broadcast_address == new_ip
5858

tests/integration/standard/test_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_schema_metadata_disable(self):
160160
self.assertEqual(len(no_token.metadata.token_map.token_to_host_owner), 0)
161161

162162
# Do a simple query to ensure queries are working
163-
query = "SELECT * FROM system.local"
163+
query = "SELECT * FROM system.local WHERE key='local'"
164164
no_schema_rs = no_schema_session.execute(query)
165165
no_token_rs = no_token_session.execute(query)
166166
self.assertIsNotNone(no_schema_rs.one())
@@ -1357,11 +1357,11 @@ def send_msg(self, msg, request_id, cb, encoder=ProtocolHandler.encode_message,
13571357

13581358
cluster.connection_class = ConnectionWrapper
13591359
s = cluster.connect()
1360-
s.execute('SELECT now() FROM system.local')
1360+
s.execute("SELECT now() FROM system.local WHERE key='local'")
13611361
s.shutdown()
13621362

13631363
for stmt in stmts:
1364-
if "SELECT now() FROM system.local" in stmt:
1364+
if "SELECT now() FROM system.local WHERE key='local'" in stmt:
13651365
continue
13661366
if "USING TIMEOUT 2000ms" not in stmt:
13671367
self.fail(f"query `{stmt}` does not contain `USING TIMEOUT 2000ms`")

tests/integration/standard/test_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def test_metrics_per_cluster(self):
377377

378378
ra = RequestAnalyzer(self.session)
379379
for _ in range(10):
380-
self.session.execute("SELECT release_version FROM system.local")
380+
self.session.execute("SELECT release_version FROM system.local WHERE key='local'")
381381

382382
for _ in range(3):
383383
try:
@@ -392,7 +392,7 @@ def test_metrics_per_cluster(self):
392392

393393
# Make sure a poorly coded RA doesn't cause issues
394394
ra = RequestAnalyzer(self.session, throw_on_success=False, throw_on_fail=True)
395-
self.session.execute("SELECT release_version FROM system.local")
395+
self.session.execute("SELECT release_version FROM system.local WHERE key='local'")
396396

397397
ra.remove_ra(self.session)
398398

tests/integration/standard/test_policies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_predicate_changes(self):
5959

6060
queried_hosts = set()
6161
for _ in range(10):
62-
response = session.execute("SELECT * from system.local")
62+
response = session.execute("SELECT * from system.local WHERE key='local'")
6363
queried_hosts.update(response.response_future.attempted_hosts)
6464

6565
self.assertEqual(queried_hosts, single_host)
@@ -70,7 +70,7 @@ def test_predicate_changes(self):
7070

7171
queried_hosts = set()
7272
for _ in range(10):
73-
response = session.execute("SELECT * from system.local")
73+
response = session.execute("SELECT * from system.local WHERE key='local'")
7474
queried_hosts.update(response.response_future.attempted_hosts)
7575
self.assertEqual(queried_hosts, all_hosts)
7676

@@ -86,7 +86,7 @@ def test_only_connects_to_subset(self):
8686
session = cluster.connect(wait_for_all_pools=True)
8787
queried_hosts = set()
8888
for _ in range(10):
89-
response = session.execute('SELECT * from system.local', execution_profile="white_list")
89+
response = session.execute("SELECT * from system.local WHERE key='local'", execution_profile="white_list")
9090
queried_hosts.update(response.response_future.attempted_hosts)
9191
queried_hosts = set(host.address for host in queried_hosts)
9292
self.assertEqual(queried_hosts, only_connect_hosts)

0 commit comments

Comments
 (0)