What is suggestions?
There are A, B, C applications. They are connected to each other from A--> B and B-->C.
The problem happens on C due to a space in a column ADDRESS2 that makes the transactions not work. After further trackback to the previous application which is A, on A application the whole address contains 36 characters and the last character. On B, the address divides into max length 35 per column hence ADDRESS2 only contains a space.
Should the A application trims every space in the last or the first character? Or the B application should delete the space? Or do you have a suggestion?
Related
I would like to create a master template that only contains one formula by using the following in B2:
=arrayformula({left(A2:A),right(A2:A)})
Where the user only enters data in column A.
Suppose I would like the user to enter data in column A, perform calculations in columns B and C, have the user enter other data in column D, and then perform one more calculation in column E.
How do I write a literal array to skip column D, so that the user can enter data there without causing: "Array result was not expanded because it would overwrite data in D2"? The following is my futile attempt at skipping column D:
=arrayformula({left(A2:A),right(A2:A),,mid(D2:D,2,1)})
This obviously yields a formula parse error.
How do I write a literal array to skip column D, so that the user can enter data there without causing: "Array result was not expanded because it would overwrite data in D2"?
Instead of using a single formula, use two formulas, one to fill columns B and C and another to fill column E.
Using a single formula will cause the error that you described.
I need your help or a little advice with my problem. For example, have a table looking like this:
blahbla 4 5 7 44
lololol 8 7 8 45
kokooko 1 2 3 4
These table has 3 lines and 4 columns, but the number of lines and columns may vary. I need to read values from this table (it is no problem with fopen) but the problem is that i dont know how to access concrete values from this table. For example if I want to printf values only from first line, or only from third column, what am I supposed to do? give me please some advice without using malloc, thanks.
Find matrix size
At first you should find the matrix size. Rows will be easy, you only have to count number of lines (I'm assuming that you are reading data from .txt file). Next thing is columns. If all rows will have the same number of elements, you can iterate over the string that is the first line and check if elements of the string are letters (for example with isalpha function). If element is a letter, then you can increment the number of columns - if not, then it will be space or number, if it is a space then you should increment number of columns variable, and if it is not then you have to skip to the next element.
If the number of elements in rows of your table may vary, then you should iterate over every line and find the number of columns like in previous case, finding the maximum.
Create matrix and copy data
Now, when you have size of your matrix you can allocate it like this: string table[numberOfRows][numberOfColumns] - then you should once again iterate over the data in txt file, checking if the element in line is alpha or is space. If it is a space and the next character is numeric(you can check it with isdigit and isspace), then you should make some string variable that you will be concatenating until it hits another space or end of line - then you assign it to matrix. If it is letter then it will be easy, just assign it to proper place in the matrix. Remeber that you will have to fill additional elements in the matrix with something like "0" (of course only if the rows can have different number of elements).
Retrieve data
You can retrieve data only from column or a row, simply create an array that has size of your table columns or rows, then you can for example iterate over your table and check if the row(column) is the one that is interesting you. And if it is, assign it to your array. Then you can print it with another loop.
I am attempting to find a way to optimize a comparison between two SHA1 values in a SQL-Server 2008 R2 database. These are currently 40 character hexadecimal values stored as char(40) within the database. The values are indexed. The list of 'known values' is comprised of 21082054 unique entries. This will be used to compare against data sets that can range in size from under a dozen to billions of entries.
As a software developer I understand that a 40 character string comparison is comparing 40 separate values, one at a time, with an early out option (As soon as they differ, the comparison ends). So the next logical step to change attempt to improve this would seem to be to move the hexadecimal value into containing integer values. This leaves me with 5 32-bit integers or 3 64-bit integers, int and long respectively for most languages these days.
What I am not sure of is how well this line of thinking translates into the SQL-Server 2008 environment. Currently the SHA1 is the Primary Key of the table. To keep that same requirement on the data I would then have to make the primary key 5 or 3 separate fields, build an index on all of those fields and then replicate these changes from the known length table to the unknown length tables.
TL;DR: Will changing a 40 character hexadecimal string into separate integer value fields increase comparison/lookup speed execution?
I doubt you have to care about that.
A 40-character string comparison is not comparing all 40 characters, unless the first 39 characters are equal.
Nearly all the time it will stop after 1 character.
Most of the rest of the time it will stop after 2.
I have a big chunk of textual data which I split and write multiple rows of a varchar(255) column of a table. Sometimes, the last character happens to be a space. When I read back this row, the trailing space is chopped and I get only 254 characters. This messes up my data when I append the next row to the end of this one.
My code sends the full 255 char (incl space) to the DB API. How can I check that the trailing space is actually written to the table?
I am not in a position to rewrite/redesign legacy code. Is there any setting - either in the DB, DB interface, read/write calls etc - that I can use to preserve the trailing space?
This is designed behaviour varchars will strip. If you want to keep all the filling spaces you have to use char columns. So the only thing you can do is change the schems
I've been trawling books online and google incantations trying to find out what fill factor physically is in a leaf-page (SQL Server 2000 and 2005).
I understand that its the amount of room left free on a page when an index is created, but what I've not found is how that space is actually left: i.e., is it one big chunk towards the end of the page, or is it several gaps through that data.
For example, [just to keep the things simple], assume a page can only hold 100 rows. If the fill-factor is stated to be 75%, does this mean that the first (or last) 75% of the page is data and the rest is free, or is every fourth row free (i.e., the page looks like: data, data, data, free, data, data, data, free, ...).
The long and short of this is that I'm getting a handle on exactly what happens in terms of physical operations that occur when inserting a row into a table with a clustered index, and the insert isn't happening at the end of the row. If multiple gaps are left throught a page, then an insert has minimal impact (at least until a page split) as the number of rows that may need to be moved to accomodate the insert is minimised. If the gap is in one big chunk in the table, then the overhead to juggle the rows around would (in theory at least) be significantly more.
If someone knows an MSDN reference, point me to it please! I can't find one at the moment (still looking though). From what I've read it's implied that it's many gaps - but this doesn't seem to be explicitly stated.
From MSDN:
The fill-factor setting applies only when the index is created, or rebuilt. The SQL Server Database Engine does not dynamically keep the specified percentage of empty space in the pages. Trying to maintain the extra space on the data pages would defeat the purpose of fill factor because the Database Engine would have to perform page splits to maintain the percentage of free space specified by the fill factor on each page as data is entered.
and, further:
When a new row is added to a full index page, the Database Engine moves approximately half the rows to a new page to make room for the new row. This reorganization is known as a page split. A page split makes room for new records, but can take time to perform and is a resource intensive operation. Also, it can cause fragmentation that causes increased I/O operations. When frequent page splits occur, the index can be rebuilt by using a new or existing fill factor value to redistribute the data.
SQL Server's data page consists of the following elements:
Page header: 96 bytes, fixed.
Data: variable
Row offset array: variable.
The row offset array is always stored at the end of the page and grows backwards.
Each element of the array is the 2-byte value holding the offset to the beginning of each row within the page.
Rows are not ordered within the data page: instead, their order (in case of clustered storage) is determined by the row offset array. It's the row offsets that are sorted.
Say, if we insert a 100-byte row with cluster key value of 10 into a clustered table and it goes into a free page, it gets inserted as following:
[00 - 95 ] Header
[96 - 195 ] Row 10
[196 - 8190 ] Free space
[8190 - 8191 ] Row offset array: [96]
Then we insert a new row into the same page, this time with the cluster key value of 9:
[00 - 95 ] Header
[96 - 195 ] Row 10
[196 - 295 ] Row 9
[296 - 8188 ] Free space
[8188 - 8191 ] Row offset array: [196] [96]
The row is prepended logically but appended physically.
The offset array is reordered to reflect the logical order of the rows.
Given this, we can easily see that the rows are appended to the free space, starting from the beginning on the page, while pointers to the rows are prepended to the free space starting from the end of the page.
This is the first time I've thought of this, and I'm not positive about the conclusion, but,
Since the smallest amount of data that can be retrieved by SQL Server in a single Read IO is one complete page of data, why would any of the rows within a single page need to be sorted in the first place? I'd bet that they're not, so that even if the gap is all in one big gap at the end, new records can be added at the end regardless of whether that's the right sort order. (if there's no reason to sort records on a page in the first place)
And, secondly, thinking about the write side of thge IO, I think the smallest write chunk is an entire page as well, (even the smallest change requires the entire page be written back to disk). This means that all the rows on a page could get sorted in memory every time the page is written to, so even if you were inserting into the beginning of a sorted set of rows on a dingle page, the whole page gets read out, the new record could be inserted into it's proper slot in the set in memory, and then the whole new sorted page gets written back to disk...