Skip to content

Commit f86514a

Browse files
committed
Use performance schema only if it is enabled.
Fix the test failures in statement_spec.rb on MariaDB 10.5. On MariaDB >= 10.0, the peformance schema is disabled. https://jira.mariadb.org/browse/MDEV-6726 And on MariaDB 10.5, the followwing code used in the test doesn't raise `Mysql2:Error`, just returning 0, even when if the performance_schema is disabled. ``` @client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances") ```
1 parent 346b4a4 commit f86514a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spec/mysql2/statement_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
@client = new_client(encoding: "utf8")
66
end
77

8+
let(:performance_schema_enabled) do
9+
performance_schema = @client.query "SHOW VARIABLES LIKE 'performance_schema'"
10+
performance_schema.any? { |x| x['Value'] == 'ON' }
11+
end
12+
813
def stmt_count
914
# Use the performance schema in MySQL 5.7 and above
10-
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
11-
rescue Mysql2::Error
12-
# Fall back to the global prepapred statement counter
13-
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
15+
if performance_schema_enabled
16+
@client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
17+
else
18+
# Fall back to the global prepapred statement counter
19+
@client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
20+
end
1421
end
1522

1623
it "should create a statement" do

0 commit comments

Comments
 (0)