Does it matter if I index a column > 900 bytes - sql

So SQL server places a limit of 900 bytes on an index. I have columns that are NVARCHAR(1000) that I need to search on. Full text search of these columns is not required because search will always occur on the complete value or a prefix of the complete value. I will never need to search for terms that lie in the middle/end of the value.
The rows of the tables in question will never be updated predicated on this index, and the actual values that exceed 450 chars are outliers that will never be searched for.
Given the above, is there any reason not to ignore the warning:
The total size of an index or primary key cannot exceed 900 bytes
?

We shouldn't ignore the warning as any subsequent INSERT or UPDATE statement that specifies data values that generates a key value longer than 900 bytes will fail. Following link might help:
http://decipherinfosys.wordpress.com/2007/11/06/the-900-byte-index-limitation-in-sql-server/

Related

Should I define a column type from actual length or nth power of 2(Sql Server )?

Should I define a column type from actual length to nth power of 2?
The first case, I have a table column store no more than 7 charactors,
will I use NVARCHAR(8)? since there maybe implicit convert inside Sql
server, allocate 8 space and truncate automatic(heard some where).
If not, NCHAR(7)/NCHAR(8), which should be(assume the fixed length is 7)
Any performance differ on about this 2 cases?
You should use the actual length of the string. Now, if you know that the value will always be exactly 7 characters, then use CHAR(7) rather than VARCHAR(7).
The reason you see powers-of-2 is for columns that have an indeterminate length -- a name or description that may not be fixed. In most databases, you need to put in some maximum length for the varchar(). For historical reasons, powers-of-2 get used for such things, because of the binary nature of the underlying CPUs.
Although I almost always use powers-of-2 in these situations, I can think of no real performance differences. There is one. . . in some databases the actual length of a varchar(255) is stored using 1 byte whereas a varchar(256) uses 2 bytes. That is a pretty minor difference -- even when multiplied over millions of rows.

Oracle: How to convert row count into data size

I would like to know how do i convert number of row into size like in MB or KB?
Is there a way to do that or formula?
The reason I doing this is because I would like to know given this set of data but not all in tablespace, how much size is used by this set of data.
Thanks,
keith
If you want an estimate, you could multiple the row count with the information from user_table.avg_row_len for that table.
If you want the real size of the table on disk, this is available user_segments.bytes. Note that the smallest unit Oracle will use is a block. So even for an empty table, you will see a value that is bigger tzen zero in that column. That is actual size of the space reserved in the tablespace for that table.

Huge join query leads to max row size error

I'm executing a SQL query that joins 100+ tables together and I am running into the following error message:
Cannot create a row of size 8131 which is greater than the allowable
maximum row size of 8060.
Just would like to know what my options are at this point? Is this query impossible to execute? Are there any workarounds?
Appreciate any help
Thanks
Your problem is not the join, or the number of tables. It is the number and size of the fields in the SELECT. You are reaching a row size limit, not a row count limit.
Make sure you are not using any "*" in your SELECT, then eliminate any unused fields and trim/limit strings where possible.
From MSDN forum:
You're hitting SQL's row size limit which is 8060 bytes (eg an 8K page). Using normal data types you cannot have a row which uses more than 8060 bytes, and while you can use a varchar to allow the smaller bits of data to offset the larger ones, with 468 columns of data you're looking at an average column width of 17.2 bytes.
If you convert varchar(x) to varchar(max) issue will be resolved.
Please also refer: How SQL server stores of the size of the row is greater than 8060 bytes Difference Between varchar(max) and varchar(8000)

How to truncate column in order to create indexes?

I have the following table in postgresql:
database=# \d dic
Table "public.dic"
Column | Type | Modifiers
-------------+-------------------------+-----------
id | bigint |
stringvalue | character varying(2712) |
database=# create index idStringvalue on dic(id,stringvalue);
ERROR: index row size 2728 exceeds maximum 2712 for index "idstringvalue"
HINT: Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.
I dont know why is the error is coming when the size of stringvalue is 2712.
I want to truncate all the stringvalue's in dic which cause the above error. However, I am not getting how to do so. Can someone please help me with this?
I am am even fine with deleting the rows which cause this error. Is there some way by which I may do so?
Your column probably contains multibyte data: whereas the varchar(2712) deals with that just fine, it kind of makes sense that the indexing algorithm would be computing the c-string length, since memory considerations is what the latter is worrying about.
Theoretically, you can't go wrong by dividing the limit by four, i.e. use an unbounded varchar for the column, and index the first 600 characters or so, e.g.:
create index on dic((left(stringvalue, 600)));
This does raise the question of whether you actually need to index anything this large, though, since the value of doing so primarily lies in sorting. Postgres (correctly) suggests that you use an md5 of the value (if you're only interested in strict equality) or full text search (if you're interested in fuzzy matching).

How much disk-space is needed to store a NULL value using postgresql DB?

let's say I have a column on my table defined the following:
"MyColumn" smallint NULL
Storing a value like 0, 1 or something else should need 2 bytes (1). But how much space is needed if I set "MyColumn" to NULL? Will it need 0 bytes?
Are there some additional needed bytes for administration purpose or such things for every column/row?
(1) http://www.postgresql.org/docs/9.0/interactive/datatype-numeric.html
Laramie is right about the bitmap and links to the right place in the manual. Yet, this is almost, but not quite correct:
So for any given row with one or more nulls, the size added to it
would be that of the bitmap(N bits for an N-column table, rounded up).
One has to factor in data alignment. The HeapTupleHeader (per row) is 23 bytes long, actual column data always starts at a multiple of MAXALIGN (typically 8 bytes). That leaves one byte of padding that can be utilized by the null bitmap. In effect NULL storage is absolutely free for tables up to 8 columns.
After that, another MAXALIGN (typically 8) bytes are allocated for the next MAXALIGN * 8(typically 64) columns. Etc. Always for the total number of user columns (all or nothing). But only if there is at least one actual NULL value in the row.
I ran extensive tests to verify all of that. More details:
Does not using NULL in PostgreSQL still use a NULL bitmap in the header?
Null columns are not stored. The row has a bitmap at the start and one bit per column that indicates which ones are null or non-null. The bitmap could be omitted if all columns are non-null in a row. So for any given row with one or more nulls, the size added to it would be that of the bitmap(N bits for an N-column table, rounded up).
More in depth discussion from the docs here
It should need 1 byte (0x00) however it's the structure of the table that makes up most of the space, adding this one value might change something (Like adding a row) which needs more space than the sum of the data in it.
Edit: Laramie seems to know more about null than me :)