locked
Do table queries perform CompareTo with CompareOptions.Ordinal? RRS feed

  • Question

  • Many partitioning strategies use CompareTo on the PK or RK for range queries.

    But the behavior of string.CompareTo depends on the current Culture. So far my tests would show that the CompareTo would behave like string.CompareOrdinal, but I wonder if I could get some official confirmation here.

    Thanks

    Tuesday, November 26, 2013 9:05 AM

Answers

  • Windows Azure Tables uses Ordinal Comparison.

    I hope this helps.

    Thanks,

    Jean

    Friday, December 6, 2013 7:27 AM

All replies

  • Hi AdditiveLabs,

    Base on my experience, "string.Compare" will call the cuture information is related to current process. When we need internationalize, I suggest you use static "string.Compare" nor ""string.CompareTo".

    "string.CompareOrdinal" will divide each five characters ( 10 bytes ) into a group , then individually compared, when the first one different ASCII codeis find, this method is exit loop.

    I suggest you could refer to the MSDN documents:

    string.Compare Compares two specified String objects and returns an integer that indicates their relative position in the sort order.

    string.CompareTo Compares this instance with a specified object or String and returns an integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified object or String.

    string.CompareOrdinal Compares two specified String objects by evaluating the numeric values of the corresponding Char objects in each string.

    Also, I have a code sample about those methods, I suggest you could test it and find their different:

    const int Num = 10000000;  
                string s1 = "abcdefgh";  
                string s2 = "abcdefgh";  
      
                //string s1 = "abcdefgh";  
                //string s2 = "amklklkl";  
                int end;  
                //Compare  
                int start = Environment.TickCount;  
                for (int i = 0; i < Num; i++)  
                {  
                    string.Compare(s1, s2);  
                }  
                end=Environment.TickCount;  
                Console.WriteLine("Compare : " + (end - start));  
      
                //CompareTo  
                start = Environment.TickCount;  
                for (int i = 0; i < Num; i++)  
                {  
                    s1.CompareTo(s2);  
                }  
                end = Environment.TickCount;  
                Console.WriteLine("CompareTo : " + (end - start));  
      
                //CompareOrdinal  
                start = Environment.TickCount;  
                for (int i = 0; i < Num; i++)  
                {  
                    string.CompareOrdinal(s1, s2);  
                }  
                end = Environment.TickCount;  
                Console.WriteLine("CompareOrdinal : " + (end - start));  
      
                //Static Equals  
                start = Environment.TickCount;  
                for (int i = 0; i < Num; i++)  
                {  
                    string.Equals(s1, s2);  
                }  
                end = Environment.TickCount;  
                Console.WriteLine("static Equals : " + (end - start));  
      
                //instance Equals  
                start = Environment.TickCount;  
                for (int i = 0; i < Num; i++)  
                {  
                    s1.Equals(s2);  
                }  
                end = Environment.TickCount;  
                Console.WriteLine("instance Equals : " + (end - start));  
    

    Hope it helps.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 27, 2013 4:57 AM
  • Thanks for your reply.

    I was rather asking for the behavior of a query performed against Windows Azure Storage Tables (that's why I posted in this particular forum). When filtering on properties, one can use the CompareTo method, so I am wondering if the Storage Table server is using a particular Culture when processing the filtering, or is using an ordinal comparison.

    Wednesday, November 27, 2013 7:41 AM
  • Hi,

    Base on my experience, the method of "CompareOrdinal"  performance is better than "CompareTo". For example, when we run those methods at the same time, the first method is faster than second one. Considering the current culture, I suggest you could use the first method.

    Thanks!

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 28, 2013 10:38 AM
  • hi AdditiveLabs,

    I will mark this this thread as answer, if you find it no help, please fell free to unmark.
    Thanks!

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 5, 2013 12:35 AM
  • Sorry but the question is still unanswered.
    Thursday, December 5, 2013 4:11 AM
  • Windows Azure Tables uses Ordinal Comparison.

    I hope this helps.

    Thanks,

    Jean

    Friday, December 6, 2013 7:27 AM