Performance of "x IN (a,b)" vs. "x = a OR x = b" [duplicate] - sql

This question already has answers here:
SQL statements with equals vs in
(2 answers)
Closed 9 years ago.
Is there likely to be any difference in performance on SQL Server between:
where (anothercolumn=17) OR (anothercolumn=23) OR (anothercolumn=33)
and
where anothercolumn IN (17,23,33)

No, they optimize exactly the same way, and you should never see any performance difference whatsoever. The only exception would be if you have a very large amount of columns and the actual network performance of transferring the query text itself introduces some latency (or exceeds the transfer size). If that happens you should hire new network people.

Related

What's the best data type to store data of a bank? [duplicate]

This question already has answers here:
Which datatype should be used for currency?
(8 answers)
Currency modeling in database
(4 answers)
Closed 3 years ago.
I was wondering what's the best data type for transaction amounts (in euro) of a bank ?
Example :
The person "A" sends 120.59 euros to "B"
What's the best data type to store this data (120.59) in a database ?
the transaction amount is positive, 2 digits after the decimal, and it will be used in calculations after (sum of amounts, averages, variance and standard-deviations...etc).
Is it okey to use REAL ? DECIMAL is ok ?
You do not want to store monetary amounts using floating point numbers.
You want to store them using fixed point -- that is numeric/decimal. For your example, it would be something like numeric(10, 2). However, you might want fractions of a cent for some reason, so larger precision and scale such as numeric(20, 4) is a good idea.

Why do I get different result on Xcode (C Language) [duplicate]

This question already has answers here:
Why does sizeof(int) vary across different operating systems?
(4 answers)
Closed 3 years ago.
long number = 100;
printf("the sizeof: %d", sizeof(number));
In Visual Studio, I get the result 4.
In Xcode, whereas I get the result 8.
Same code, different result. Could you tell me why I get this result?
See here: long is guaranteed by the standard to be "at least 32 bits", and depending on the data model may be bigger.
If you want "exactly 32 bits", try if int32_t is supported.

Big O notation of a constant larger than 1 [duplicate]

This question already has an answer here:
Why do we prefer not to specify the constant factor in Big-O notation?
(1 answer)
Closed 3 years ago.
Does it mean anything at all to have a function with time complexity O(2)?
For example, how would one describe a function that must check two lookup tables rather than one. Is that not strictly describable in big-O, or is O(2) a real way to describe this? Or something else?
Thanks.
O(something) is a set of functions.
O(1) and O(2) are the same set.
A constant time function is a member of O(1). It's also a member of O(2) because O(1) and O(2) are exactly the same thing. Use whichever one you prefer. Normally you'd use O(1), but you be you.

Is there a Objective-C or C math function to constrain a variable between a Min and a Max? [duplicate]

This question already has answers here:
Fastest way to clamp a real (fixed/floating point) value?
(14 answers)
Closed 6 years ago.
What I am looking for is a math function that constrains a primitive variable between a minimum and a maximum value in only one single function call, if it exists, in the standard math libraries for Objective-C.
I currently use:
float constrainedValue = fminf( maxValue, fmaxf( minValue, inValue ) );
Since I know that both fminf and fmaxf could potentially have instruction jumps or branches, it seems likely there could be a simple routine that could conjoin both of these operations into one, optimized function.
This topic is thoroughly discussed here: Fastest way to clamp a real (fixed/floating point) value?
'clamp' is the keyword I was looking for.

What are typical lengths of chat message and comment in database? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I need to create a column in SQL Server database. Entries for that column will contain messages from chat. Previously such messages has been stored as comments.
My main quetion is:
What is typical text length for chat message and comment?
By the way:
What would happen if I used varchar(max)? How would it impact database size and performance? Is better to use powers of 2 or powers of 10 (e.g. 128 instead of 100) while considering text lengths?
Using VARCHAR(MAX) has a disadvantage: you can not define an index over this column.
Generally, your application should impose a maximum length for a chat message. How big that limit is depends very much on what the application is used for. But anything more than 1000 byte is probably less a legitimate message but an attempt to disrupt your service.
If your maximum value is a power of 2, or a power of ten or any other value has no influence on the performance as long as the row fits in one (8KB) page.
Short answer - it doesn't matter.
From MSDN:
The storage size is the actual length of the data entered + 2 bytes.
So VARCHAR(10) and VARCHAR(10000) will consume the same amount of data if the values don't exceed 10 characters.
Definitely use N/VARCHAR(MAX), it can grow to be 2GB (if I remember correctly). It will grow as required though, so it is very efficient with regards to space unless you are only storing very small amounts of data.