Incorrect exprDataType value to select for varchar partitioning key

Bug #1220100 reported by Alvin Peng
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Stado
Fix Committed
Undecided
Unassigned

Bug Description

Stado is built with revision 107 from lp:~sgdg/stado/stado.

# table:
create table dnsinfo (mid varchar(16), sip bigint, dip bigint);

# data
file dns.dat:
1376983262,0,0

# load data
./gs-loader.sh -u admin -p admin -d xtest -t dnsinfo -f ',' -i dns.dat

# insert data
insert into dnsinfo values('1376983263',0,0);

# query
Stado -> select * from dnsinfo;
+------------------------+
| mid | sip | dip |
+------------------------+
| 1376983262 | 0 | 0 |
| 1376983263 | 0 | 0 |
+------------------------+
2 row(s).

Above query works correctly. But

Stado -> select * from dnsinfo where mid = '1376983263';
no rows to display

With "where" condition, no row is displayed.

In SqlExpression.java,
public String getNormalizedValue() {
{code}...
    case Types.VARCHAR:
     if (getExprDataType().length > 0
       && normalized.length() > getExprDataType().length) {
      normalized = normalized.substring(0,
        getExprDataType().length);
     }
     return normalized;
{code}...

For load and insert, the exprDataType from getExprDataType() has length 16, which is correct.
For select query with where condition, the exprDataType has length 5, so the normalized value is "13769".

Then partitionMap.getPartitions(sValue), incorrect partition node is get with an incorrect hash key value.
Thus, the query result is incorrect.

Related branches

Revision history for this message
Alvin Peng (pengalvin) wrote :

In SysColumn.java:

    /**
     * Returns the column length in bytes
     */
    public int getColumnLength() {
        int colLength;

        switch (this.coltype) {
        case java.sql.Types.BIT:
            colLength = 1;
            break;

        case java.sql.Types.CHAR:
            colLength = this.collength;
            break;

        case java.sql.Types.VARCHAR:
            colLength = this.collength / 3;
            break;
{code}...

the length is divided by 3.

This could be the root cause.

Revision history for this message
Alvin Peng (pengalvin) wrote :

From the function's comments "Returns the column length in bytes",

case java.sql.Types.VARCHAR:
            colLength = this.collength / 3;
            break;

it should not be divided by 3. Update to:

case java.sql.Types.VARCHAR:
            colLength = this.collength;
            break;

Revision history for this message
Alvin Peng (pengalvin) wrote :

After the code change, query is correct:

Stado -> select * from dnsinfo where mid = '1376983263';
+------------------------+
| mid | sip | dip |
+------------------------+
| 1376983263 | 0 | 0 |
+------------------------+
1 row(s).

Revision history for this message
Andrei Martsinchyk (andrei-martsinchyk) wrote :

Commited. Thanks for the report and for the fix.

Changed in stado:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.