Reputation: 5436
I have the following 2 Python codes:
def direct_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id % {0} = {1}'''.format(partition_size, node)
and then
def find_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id %% {0} = {1}'''.format(partition_size, node)
I am wondering what % and %% in the 2 MySQL queries are about?
Edit:
When I try %% in MySQL Workbench, looks like I have a syntax error, looks like %% is invalid.
Upvotes: 1
Views: 81
Reputation: 1238
The first one is a Modulo operation and calculates the remainder of id divided by partition_size then compare it with node.
Look at a simple example here:
mysql> SELECT 253 % 7;
-> 1 # because 253 = 36*7 + 1
As you noticed %% is not a valid operator.
Upvotes: 1