comparisons vs exchanges

  • for a computer what is more expensive, comparisons or exchanges.

  • You'll have to define the context in which you're using these terms. For example, you say comparison and I think that you're referring to the WHERE clause or the JOIN clause TSQL criteria for comparing two values:

    WHERE a.ColX = 42

    In this case, the cost of the comparison depends on a lot of factors, data types, existence of indexes, condition of statistics, comparison operators, just to name a few. So what is the term we're talking about.

    Exchange, at least when thinking about TSQL, doesn't seem to be an apples to apples comparison to comparison.

    So please, define the terms and context a bit more.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • actually what i meant is this, you go through set of values to find a particular value inside that set is comparison,

    and while comparing if you want to exchange two values within that it is called exchanges.(this could be done by swapping these two values)

    i thnk now it is clear.

  • smsam1 (6/29/2009)


    actually what i meant is this, you go through set of values to find a particular value inside that set is comparison,

    That would be a WHERE clause within a select statement. Pretty straight forward stuff.

    [/quote]

    and while comparing if you want to exchange two values within that it is called exchanges.(this could be done by swapping these two values)

    i thnk now it is clear.[/quote]

    That sure sounds like an UPDATE statement.

    You can do both at the same time:

    UPDATE colx = 'new value' FROM tabley WHERE colx = 'old value'

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • To build on what Grant and others have said. Exchanges are, in general, more expensive. Since we are talking in a SQL forum, I'll assume that you mean as it pertains to SQL Server.

    As Grant showed you do an UPDATE with a WHERE clause which is both and exchange and a comparison:UPDATE colx = 'new value' FROM tabley WHERE colx = 'old value'

    You can also achive the same thing by doing just exchanges, but it is going to be much less performant than using a comparison in your UPDATE:UPDATE

    colx = CASE WHEN colx = 'old value' THEN 'new value' ELSE colx END

    FROM tabley Hopefully, my example makes sense. If you have more questions or want clarifications, feel free to ask.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply