大数据量的查询
1.用临时表
2.用存储过程
3.建索引
-- =============================================
-- Author: Ylem
-- Create date: 2009-12-23
-- Description: 得到导入简历列表
-- =============================================
alter PROCEDURE [dbo].[proc_GetImportResumeBaseByconditions2]
(
@ConditionSql varchar(3000),
@Size int,
@index varchar(10),
@count int output
)
AS
BEGIN
--SET NOCOUNT ON;
DECLARE @sql nvarchar(4000)
CREATE TABLE #ResumeBase (
ResumeID uniqueidentifier PRIMARY KEY
,JobSeekerID uniqueidentifier
,ResumeCode varchar(64)
,ResumeSourceSite varchar(20)
,ResumeSourceID varchar(64)
,UpdateDate datetime
,CreateDate datetime
,AuditStatue Smallint)
CREATE TABLE #BuyResume(ResumeID uniqueidentifier PRIMARY KEY, Quantity int)
INSERT INTO #BuyResume(ResumeID, Quantity)
SELECT ResumeID, COUNT(*) Quantity
FROM BuyNoContactResume
GROUP BY ResumeID
INSERT INTO #ResumeBase
EXEC (@ConditionSql)
CREATE INDEX IX_ResumeBaseTemp_JobSeekerID ON #ResumeBase(JobSeekerID ASC);
CREATE TABLE #TempRecord (IndexID int /*IDENTITY (1, 1) NOT NULL primary key*/,
ResumeID uniqueidentifier
,ResumeCode varchar(64)
,ResumeSourceSite varchar(20)
,ResumeSourceID varchar(64)
,UpdateDate datetime
,CreateDate datetime
,CityID varchar(20)
,ContactState tinyint
,Sex bit
,Age int
,Degree int
,LastLoginDate datetime
,AuditStatue smallint)
SET @sql = '
SELECT IndexID = ROW_NUMBER() OVER(ORDER BY CreateDate), t.*
FROM (
SELECT
rb.ResumeID
,rb.ResumeCode
,rb.ResumeSourceSite
,rb.ResumeSourceID
,rb.UpdateDate
,rb.CreateDate
,i.CityID
,i.ContactState
,i.Sex
,datediff(yy,i.Birthday,getdate()) Age
,i.Degree
,u.LastLoginDate
,rb.AuditStatue
FROM
#ResumeBase rb
JOIN JobSeekerInfo i ON i.JobSeekerID = rb.JobSeekerID
join jobseekeruser u on u.JobSeekerID = rb.JobSeekerID
WHERE i.ContactState =0
) t'
INSERT INTO #TempRecord
EXEC (@sql)
--返回统计数
SELECT @count = max(IndexID) from #TempRecord
--返回数据
SELECT * FROM #TempRecord tmp
WHERE IndexID > (@index*@Size) and IndexID<=((@index + 1) * @Size)
DROP TABLE #TempRecord
END