SQL Server database paging query has been a short board of SQL Server, idle, come up with several methods, assuming that there are table article, Field ID, year ... (other omitted), Data 53,210 (customer real data, quantity is not large), paging query each page 30, query page 1500th (ie 第45001-45030条 data), field ID clustered index, Year no index, SQL Server version: 2008R2
The first scenario, the simplest, the common method:
Copy code code as follows:
Select Top * from ARTICLE WHERE ID. (sel
("@OrderField", sqldbtype.nvarchar,200),
New SqlParameter ("@OrderType", sqldbtype.nvarchar,2),
New SqlParameter ("@TableName", sqldbtype.nvarchar,300),
New SqlParameter ("@strWhere", sqldbtype.nvarchar,300),
};
Parameters[0]. Direction = ParameterDirection.Output;
PARAMETERS[1]. Direction = ParameterDirection.Output;
PARAMETERS[2]. Value = pageSize;
PARAMETERS[3]. Value = CurrentPage;
PARAMETERS[4]. Value = "A.rlid,a.companyname,a.website,a.isrl,a.ordernum,a.isrl,a.userid";
PARAMETERS[5]. Valu
unnecessary context switching can be balanced with innodb_sync_spin_loops.The following section shows the deadlock condition:1.------------------------2.LATEST detected DEADLOCK3.------------------------4.060717 4:16:485.*** (1) TRANSACTION:6.TRANSACTION 0 42313619, ACTIVE sec, Process no 10099, OS thread ID 3771312 starting index read7.mysql tables in use 1, locked 18.LOCK WAIT 3 LOCK struct (s), Heap size 3209.MySQL thread ID 30898, query id 100626 localhost root Updating10.update iz set pad=
How to write SQL statements for such requirements? A sorted SQL statement
Sort by status field in reverse order
If the status = 1 time field is in positive order, if the status = 0 time field is in reverse order
The following are the expected results.
Id status time
5 1 50
6 1 51
1 0 99
10 0 1
Reply to discussion (solution)
Select * from (select * from table where status = 1 order by time) aunion allselect * from (select * from table where status = o order by time desc) B
dictionary which should retain the maximum number of rows in the database select count (*) FROM ipdatas WHERE uid = 1; return result time: 2 minutes 31 seconds 594Select count (id) FROM ipdatas WHERE uid = 1; return result time: 1 minute 29 seconds 609Select count (uid) FROM ipdatas WHERE uid = 1; return result time: 2 minutes 41 seconds 813The second query is faster. because mysql has a cache area, increasing the cache area size can solve many query optimizations, the cache is everywhere. In p
", sqldbtype.nvarchar,50),
New SqlParameter ("@OrderField", sqldbtype.nvarchar,200),
New SqlParameter ("@OrderType", sqldbtype.nvarchar,2),
New SqlParameter ("@TableName", sqldbtype.nvarchar,300),
New SqlParameter ("@strWhere", sqldbtype.nvarchar,300),
};
Parameters[0]. Direction = ParameterDirection.Output;
PARAMETERS[1]. Direction = ParameterDirection.Output;
PARAMETERS[2]. Value = pageSize;
PARAMETERS[3]. Value = CurrentPage;
PARAMETERS[4]. Value = "A.rlid,a.companyname,a.website,a.
The first scenario, the simplest, the common method:
Copy Code code as follows:
Select Top * from ARTICLE WHERE ID. (select top 45000 ID to ARTICLE order by year DESC, id DESC) Esc,id DESC
Average Enquiry 100 Time: 45s
The second option:
Copy Code code as follows:
SELECT * FROM (select top 45030 * from ARTICLE, DESC, ID DESC) F ORDER by F.year ASC, F.id DESC) s ORDER by S.year Desc,s.id DESC
Average
increase the size of the buffer can solve a lot of query optimization, is really a cache everywhere AH in the program development is also a layer of cacheQuerying data
The code is as follows
Copy Code
First start query SELECT * FROM Ipdatas ORDER by ID DESC LIMIT 1,10; 31 ms SELECT * from IP Datas LIMIT 1,10; 15MS 10,000th start query SELECT * from Ipdatas ORDER by ID ASC LIMIT 10000,10; 266 cents SEC SELEC
(FLNM)
Lngsize = Objftemp.size
Set objftemp = Nothing
fsoforreading = 1
Set objTextStream = objFSO.OpenTextFile (flnm, fsoforreading)
If offset > 0 Then
Strbuff = Objtextstream.read (offset-1)
End If
If bytes =-1 Then ' Get all!
GetBytes = Objtextstream.read (lngsize) ' ReadAll
Else
GetBytes = Objtextstream.read (bytes)
End If
Objtextstream.close
Set objTextStream = Nothing
Set objFSO = Nothing
End Function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
':: Funct
SQL Server database paging query has always been a short board of SQL Server, so I have nothing to worry about. I have come up with several methods, for example, table ARTICLE, field ID, YEAR... (others omitted). There are 53210 million pieces of data (the customer's actual data is not big), 30 pieces of data are queried by PAGE, 1,500th pages are queried (that is, the 45001-20.30 pieces of data), and the field ID is clustered index, YEAR: No index. Sqlserver version: 2008R2
The first solution,
After repeated regions are added, you can add them in ascending order. if you want to add repeated regions on a webpage, 50 entries of information cannot be displayed in ascending order. The old information at the bottom of the page is at the top of the page. However, when more than 50 pieces of information are added, 1-50 pieces of information are displayed on the page. I don't want to display any old information when I add a new message. Thank you.
Reply to discussion (solution)
If it is
SQL Server database paging query has always been a short board of SQL Server, so I have nothing to worry about. I have come up with several methods, for example, table ARTICLE, field ID, YEAR... (others omitted). There are 53210 million pieces of data (the customer's actual data is not big), 30 pieces of data are queried by PAGE, 1,500th pages are queried (that is, the 45001-20.30 pieces of data), and the field ID is clustered index, YEAR: No index. Sqlserver version: 2008R2The first solution, t
The first solution, the simplest and common method:
Copy codeThe Code is as follows:Select top 30 * from article where id not in (select top 45000 id from article order by year desc, id desc) order by year desc, ID DESC
Average query time: 45 s
Solution 2:
Copy codeThe Code is as follows:SELECT * FROM (select top 30 * FROM (select top 45030 * from article order by year desc, id desc) f order by f. year asc, f. id desc) s order by s. year desc, s. ID D
The first solution, the simplest and common method:
Copy codeThe Code is as follows: select top 30 * from article where id not in (select top 45000 id from article order by year desc, id desc) order by year desc, ID DESC
Average query time: 45 s
Solution 2:
Copy codeThe Code is as follows: SELECT * FROM (select top 30 * FROM (select top 45030 * from article order by year desc, id desc) f order by f. year asc, f. id desc) s order by s. year desc, s.
OPTION EXPLICIT
Const BASE_64_MAP_INIT =
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim nl
' Zero based arrays
Dim Base64encmap (63)
Dim Base64decmap (127)
' must be called before using anything else
Public SUB Initcodecs ()
' Init VARs
NL = "' Setup Base 64
Dim max, IDX
max = Len (base_64_map_init)
For idx = 0 to Max-1
' One based string
Base64encmap (IDX) = Mid (Base_64_map_init, IDX + 1, 1)
Next
For idx = 0 to Max-1
Base64decmap (
Encryption Bigeagle was posted at Joy asp↑ in 2000-11-9 10:48:18:
OPTION EXPLICIT
Const BASE_64_MAP_INIT =
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim nl
' Zero based arrays
Dim Base64encmap (63)
Dim Base64decmap (127)
' must be called before using anything else
Public SUB Initcodecs ()
' Init VARs
NL = "' Setup Base 64
Dim max, IDX
max = Len (base_64_map_init)
For idx = 0 to Max-1
' One based string
Base64encmap (IDX) = Mid (Base_64_map_init, IDX + 1, 1)
Next
For id
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.