Skip to content

Commit

Permalink
release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
akuzminsky committed Feb 23, 2017
2 parents 2da8dc0 + 2002868 commit fc1879a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.1.0
current_version = 1.1.1
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -18,7 +18,7 @@

setup(
name='twindb_table_compare',
version='1.1.0',
version='1.1.1',
description="TwinDB Table Compare reads percona.checksums from the master "
"and slave and shows what records are difference "
"if there are any inconsistencies.",
Expand Down
2 changes: 1 addition & 1 deletion twindb_table_compare/__init__.py
Expand Up @@ -8,7 +8,7 @@

__author__ = 'Aleksandr Kuzminsky'
__email__ = 'aleks@twindb.com'
__version__ = '1.1.0'
__version__ = '1.1.1'

LOG = logging.getLogger(__name__)

Expand Down
37 changes: 35 additions & 2 deletions twindb_table_compare/compare.py
Expand Up @@ -196,6 +196,34 @@ def get_fileds(conn, db, tbl):
return ', '.join(fields)


def primary_exists(conn, db, tbl):
"""
Check if PRIMARY index exists in table db.tbl
:param conn: MySQLdb connection.
:type conn: Connection
:param db: Database name.
:type db: str
:param tbl: Table name.
:type tbl: str
:return: True if index PRIMARY exists in table db.tbl
:rtype: bool
"""
query = "SELECT COUNT(*)" \
"FROM INFORMATION_SCHEMA.STATISTICS " \
"WHERE TABLE_SCHEMA = %s " \
"AND TABLE_NAME = %s" \
"AND INDEX_NAME = 'PRIMARY'"
cursor = conn.cursor()
cursor.execute(query, (db, tbl))

n_fields = cursor.fetchone()[0]

LOG.debug('Number of fields in PRIMARY index %d', n_fields)

return bool(n_fields > 0)


# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
def build_chunk_query(db,
tbl,
Expand Down Expand Up @@ -283,8 +311,13 @@ def build_chunk_query(db,
where += " 1"

fields = get_fileds(conn, db, tbl)
query = "SELECT %s FROM `%s`.`%s` USING (PRIMARY) %s" \
% (fields, db, tbl, where)
if primary_exists(conn, db, tbl):
index_hint = "USE INDEX (PRIMARY)"
else:
index_hint = ""

query = "SELECT %s FROM `%s`.`%s` %s %s" \
% (fields, db, tbl, index_hint, where)

return query

Expand Down

0 comments on commit fc1879a

Please sign in to comment.