Skip to main content

Posts

Re: JSON document fast lookup with MySQL 5.7

This is a response to the JSON document fast lookup with MySQL 5.7 article by Frederic Descamp. It is very easy to also use MySQL Workbench and the new GeoJSON support to actually show the features. My query: SELECT ST_GeomFromGeoJSON(feature->"$.geometry",2) AS feature  FROM test_features WHERE street='BEACH' ; The result:  

When simple SQL can be complex

I think SQL is a very simple language, but ofcourse I'm biased. But even a simple statement might have more complexity to it than you might think. Do you know what the result is of this statement? SELECT FALSE = FALSE = TRUE; scroll down for the answer. The answer is: it depends. You might expect it to return false because the 3 items in the comparison are not equal. But that's not the case. In PostgreSQL this is the result: postgres=# SELECT FALSE = FALSE = TRUE; ?column? ---------- t (1 row) So it compares FALSE against FALSE, which results in TRUE and then That is compared against TRUE, which results in TRUE. PostgreSQL has proper boolean literals . Next up is MySQL: mysql> SELECT FALSE = FALSE = TRUE; +----------------------+ | FALSE = FALSE = TRUE | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec) This is similar but it's slightly different. The result is 1 because in My...

Using Connector/J with Python

With Python you would normally use MySQL Connector/Python or the older MySQLdb to connect from Python to MySQL, but there are more options. There are also multiple Python implementations: CPython (the main implementation), PyPy , Jython and IronPython . PyPy tries to be faster than CPython by using a Just-in-Time compiler. Jython runs on the JVM and IronPython runs on the .NET CLR . Connector/Python by default (Without the C Extension) is a pure Python implementation and can work with most if not all implementations. And for MySQLdb there is a drop-in replacement called PyMySQL , which is a pure python implementation. So there are many options already. But for at least Jython it is also possible to use a Java (JDBC) driver. But why would you use a different Python implementation? There are multiple reasons for that: Speed. PyPy can be faster and Jython has no Global Interpreter Lock (GIL) , which can allow for more concurrent execution. To access 'native' code. e.g. ca...

The performance of TLS with MySQL Connector/Python

I've ran a simple test to see the performance impact of TLS on MySQL connections with MySQL Connector/Python The test results are in this Jupyter notebook . TL;DR: Try to reuse connections if you use TLS Establishing TLS connections is expensive (server & client) Improved performance might be possible in the future by using TLS Tickets Not tested: Difference between YaSSL and OpenSSL Difference between Ciphersuites Performance of larger resultsets and queries

The performance of MySQL Connector/Python with C Extension

The source of this post is in this gist on nbviewer. After reading about the difference between MySQL Connector/Python and MySQLdb on this blog post I wondered how the C Extension option in Connector/Python would perform. If you want to run the code yourself you'll need: Jupyter/IPython, Python 3, Requests, MySQLdb, Connector/Python, Matplotlib, Pandas and MySQL. In [1]: % matplotlib notebook In [2]: import random import gzip import time import pandas as pd import matplotlib.pyplot as plt import requests import mysql.connector import MySQLdb for imp in [ mysql . connector , MySQLdb ]: print ( 'Using {imp} {version}' . format ( imp = imp . __name__ , version = imp . __version__ )) print ( 'C Extension for MySQL Connector/Python available: %s' % mysql . connector . HAVE_CEXT ) Using mysql.connector 2.1.3 Using MySQLdb 1.3.7 C Extension ...