Skip to content

Commit bcdd25b

Browse files
authored
Remove set_options from stats-gathering query to improve its performance (#7)
* Remove set_options from stats-gathering query to improve its performance * Upgrade Confluent lib so ARM64 builds will work
1 parent c4559e1 commit bcdd25b

File tree

6 files changed

+4
-20
lines changed

6 files changed

+4
-20
lines changed

plan_monitor/collect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def poll_db(db_identifier: str, odbc_conn_string: str, stop_event: mp.Event,
5454
"db_identifier": db_identifier,
5555
"plan_handle": f'0x{row.plan_handle.hex()}',
5656
"sql_handle": f'0x{row.sql_handle.hex()}',
57-
"set_options": row.set_options,
5857
"creation_time": int(row.creation_time.replace(tzinfo=db_tz).timestamp() * 1000),
5958
"last_execution_time": int(
6059
row.last_execution_time.replace(tzinfo=db_tz).timestamp() * 1000),

plan_monitor/detect.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ def detect() -> None:
198198
db_identifier: str = msg_val['db_identifier']
199199
sql_handle: str = msg_val['sql_handle']
200200
stats_query_time: int = msg_val['stats_query_time']
201-
set_options: int = msg_val['set_options']
202201
msg_coordinates: str = common.msg_coordinates(msg)
203202

204203
caught_up: bool = time.time() - (stats_query_time / 1000) < config.MAX_ALLOWED_EVALUATION_LAG_SECONDS
@@ -220,7 +219,6 @@ def detect() -> None:
220219
out_msg_val['prior_plans'] = [p.to_dict() for p in prior_plans]
221220
out_msg_val['db_identifier'] = db_identifier
222221
out_msg_val['sql_handle'] = sql_handle
223-
out_msg_val['set_options'] = set_options
224222
out_msg_key = message_schemas.key_from_value(msg_val)
225223
try:
226224
kafka_producer.produce(topic=config.BAD_PLANS_TOPIC, key=out_msg_key, value=out_msg_val)

plan_monitor/message_schemas.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ def get_key_schema(record_name: str) -> str:
1717
"name": "db_identifier",
1818
"type": "string"
1919
},
20-
{
21-
"name": "set_options",
22-
"type": "int"
23-
},
2420
{
2521
"name": "sql_handle",
2622
"type": "string"
@@ -31,7 +27,6 @@ def get_key_schema(record_name: str) -> str:
3127

3228
def key_from_value(message_value: Dict[str, Any]) -> Dict[str, Any]:
3329
return {"db_identifier": message_value["db_identifier"],
34-
"set_options": message_value["set_options"],
3530
"sql_handle": message_value["sql_handle"]}
3631

3732

@@ -52,10 +47,6 @@ def key_from_value(message_value: Dict[str, Any]) -> Dict[str, Any]:
5247
"name": "sql_handle",
5348
"type": "string"
5449
},
55-
{
56-
"name": "set_options",
57-
"type": "int"
58-
},
5950
{
6051
"name": "creation_time",
6152
"type": "long",
@@ -117,7 +108,7 @@ def key_from_value(message_value: Dict[str, Any]) -> Dict[str, Any]:
117108
})
118109

119110
PRIOR_PLANS_SCHEMA = [x for x in SINGLE_PLAN_STATS_FIELDS
120-
if x['name'] not in ('db_identifier', 'sql_handle', 'set_options')]
111+
if x['name'] not in ('db_identifier', 'sql_handle')]
121112

122113
BAD_PLANS_MESSAGE_VALUE_AVRO_SCHEMA = json.dumps({
123114
"name": "bad_plans_value",

plan_monitor/queries.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
SELECT
2323
qs.plan_handle AS plan_handle
2424
, qs.sql_handle AS sql_handle
25-
, CAST(epa.value AS INT) AS set_options
2625
, MIN(qs.creation_time) AS creation_time
2726
, MAX(qs.last_execution_time) AS last_execution_time
2827
, MAX(qs.execution_count) AS execution_count
@@ -37,9 +36,7 @@
3736
, GETDATE() AS stats_query_time
3837
FROM recent_plans
3938
JOIN sys.dm_exec_query_stats AS qs ON (recent_plans.plan_handle = qs.plan_handle)
40-
CROSS APPLY sys.dm_exec_plan_attributes(qs.plan_handle) AS epa
41-
WHERE epa.attribute = 'set_options'
42-
GROUP BY qs.plan_handle, qs.sql_handle, epa.value
39+
GROUP BY qs.plan_handle, qs.sql_handle
4340
)
4441
SELECT * FROM agged
4542
WHERE (total_logical_writes = 0 OR statement_count > 1)
@@ -51,7 +48,6 @@
5148
class StatsDmvsQueryResult(NamedTuple):
5249
plan_handle: bytes
5350
sql_handle: bytes
54-
set_options: int
5551
creation_time: datetime
5652
last_execution_time: datetime
5753
execution_count: int

plan_monitor/stats_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __len__(self) -> int:
5656

5757
def register_stats_from_message(self, msg: Dict[str, Any],
5858
msg_coordinates: str) -> List[PlanStats]:
59-
query_key = (msg["db_identifier"], msg["set_options"], msg["sql_handle"])
59+
query_key = (msg["db_identifier"], msg["sql_handle"])
6060
current_stats = PlanStats(
6161
msg["plan_handle"], msg['creation_time'], msg['last_execution_time'], msg['stats_query_time'],
6262
msg['statement_count'], msg['execution_count'], msg['total_elapsed_time'], msg['total_logical_reads'],

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
confluent-kafka[avro]==1.8.2
1+
confluent-kafka[avro]==2.6.0
22
markupsafe==2.0.1
33
pyodbc==4.0.32
44
python-dateutil==2.8.2

0 commit comments

Comments
 (0)