Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 MOD - Recent Topics (was BUG? Recent Topics)
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 5

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 April 2002 :  23:11:51  Show Profile  Send ruirib a Yahoo! Message
Yes, it probably should. Here, I've changed it:

SELECT TOP 10 * FROM
(SELECT DISTINCT FORUM_TOPICS.TOPIC_ID, FORUM_TOPICS.T_SUBJECT, FORUM_REPLY.R_AUTHOR, (SELECT TOP 1 R_DATE FROM FORUM_REPLY WHERE (FORUM_REPLY.TOPIC_ID = FORUM_TOPICS.TOPIC_ID AND FORUM_REPLY.R_AUTHOR=5 AND R_DATE IN (SELECT R_DATE FROM FORUM_REPLY WHERE R_AUTHOR=5 AND R_DATE < 20020219235900)) ORDER BY R_DATE DESC) AS R_DATE
FROM FORUM_REPLY AS FORUM_REPLY INNER JOIN FORUM_TOPICS AS FORUM_TOPICS ON FORUM_REPLY.TOPIC_ID = FORUM_TOPICS.TOPIC_ID
WHERE FORUM_REPLY.R_AUTHOR=5 AND R_DATE < 20020219235900

UNION

SELECT DISTINCT FORUM_TOPICS.TOPIC_ID, FORUM_TOPICS.T_SUBJECT, FORUM_TOPICS.T_AUTHOR, FORUM_TOPICS.T_DATE
FROM FORUM_TOPICS AS FORUM_TOPICS LEFT JOIN FORUM_REPLY AS FORUM_REPLY ON FORUM_TOPICS.TOPIC_ID=FORUM_REPLY.TOPIC_ID
WHERE (FORUM_TOPICS.T_AUTHOR=5 AND FORUM_REPLY.TOPIC_ID Is Null ) OR (FORUM_TOPICS.T_AUTHOR=5 AND FORUM_REPLY.TOPIC_ID Not In (SELECT TOPIC_ID FROM FORUM_REPLY WHERE R_AUTHOR=5)) )
AS MY_VIEW
WHERE R_DATE < 20020219235900
ORDER BY R_DATE DESC;


I also found this one is more correct (small bug on the previous one, the condition in the subquery is needed to get the correct results...
Let me know about the results for this one...

Btw, nice work on the testing. Always good to know real execution data. One thing I'd like to know, though - how many posts are really selected (before selecting the last 10, I mean...)

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Aaron S.
Average Member

USA
985 Posts

Posted - 22 April 2002 :  23:20:42  Show Profile  Visit Aaron S.'s Homepage
It is returning 1160 records before the 10 are pulled out.

The new query you posted doesn't seem to work.

In ASP, it is returning the wrong data, and in Access it doesn't show any data.

--Aaron


MySubs Email MOD
MOD to Smile Mgr
HotKeys MOD
Go to Top of Page

Aaron S.
Average Member

USA
985 Posts

Posted - 22 April 2002 :  23:23:08  Show Profile  Visit Aaron S.'s Homepage
Ok... I got it to work.

In the query you posted it had "<" before the date, and I have been using ">".

The new query seems to load between .14 - .17.

BTW: I have been testing this locally using Access, when I uploaded the pages to my actual site (which uses SQL Server), I get this error:

Microsoft OLE DB Provider for SQL Server error '80040e14'

The identifier that starts with 'SELECT DISTINCT FORUM_TOPICS.TOPIC_ID,FORUM_TOPICS.T_SUBJECT,FORUM_TOPICS.T_STATUS,FORUM_TOPICS.T_LAST_POST,FORUM_TOPICS.T_REPLI'

is too long. Maximum length is 128.


--Aaron

MySubs Email MOD
MOD to Smile Mgr
HotKeys MOD

Edited by - aaron s. on 22 April 2002 23:24:26

Edited by - aaron s. on 22 April 2002 23:30:37
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 April 2002 :  23:46:09  Show Profile  Send ruirib a Yahoo! Message
Well, this one seems to be slower...

And I don't know what to do with that size limit. Looks like an ADO limitation. Too bad.
It also looks like your mixed SQL / Vb solution is the way to go...


-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 23 April 2002 :  18:04:50  Show Profile  Send ruirib a Yahoo! Message
Aaron,

I forget to wrote yesterday that there is another alternative: transform the SQL instruction into a stored procedure for SQL Server or a query for Access. That will have the aditional benefit of producing even faster results, as the SQL will already have been compiled and execution will be faster than the submission of a normal SQL command.

It will, however, have the obvious disadvantage of difficulting its use in a mod, but that can be overcome for the more experienced users.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Aaron S.
Average Member

USA
985 Posts

Posted - 23 April 2002 :  18:27:41  Show Profile  Visit Aaron S.'s Homepage
Since I just starting using SQL Server, I am not that familar with stored procedures.

BUT, it is definitely something that I would like to know more about, since I know it can dramatically improve performance.

This MOD seems like a good place for me to start.

--Aaron

MySubs Email MOD
MOD to Smile Mgr
HotKeys MOD
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 23 April 2002 :  18:46:00  Show Profile  Send ruirib a Yahoo! Message
It's really pretty simple to create and execute one. You can create it using Enterprise Manager or Query Analizer.
Let's just say you use EM:

1. Open your DB in EM expand it and right click Stored Procedures.
2. Choose New Stored Procedure
3. Paste the code :


CREATE PROCEDURE pPost
@startDate nvarchar(50),
@mID int

AS

SELECT TOP 10 * FROM
(SELECT DISTINCT FORUM_TOPICS.TOPIC_ID, FORUM_TOPICS.T_SUBJECT, FORUM_REPLY.R_AUTHOR, (SELECT TOP 1 R_DATE FROM FORUM_REPLY WHERE (FORUM_REPLY.TOPIC_ID = FORUM_TOPICS.TOPIC_ID AND FORUM_REPLY.R_AUTHOR=@mId AND R_DATE IN (SELECT R_DATE FROM FORUM_REPLY WHERE R_AUTHOR=@mId AND R_DATE > @startDate)) ORDER BY R_DATE DESC) AS R_DATE
FROM FORUM_REPLY AS FORUM_REPLY INNER JOIN FORUM_TOPICS AS FORUM_TOPICS ON FORUM_REPLY.TOPIC_ID = FORUM_TOPICS.TOPIC_ID
WHERE FORUM_REPLY.R_AUTHOR=@mId AND R_DATE > @startDate

UNION

SELECT DISTINCT FORUM_TOPICS.TOPIC_ID, FORUM_TOPICS.T_SUBJECT, FORUM_TOPICS.T_AUTHOR, FORUM_TOPICS.T_DATE
FROM FORUM_TOPICS AS FORUM_TOPICS LEFT JOIN FORUM_REPLY AS FORUM_REPLY ON FORUM_TOPICS.TOPIC_ID=FORUM_REPLY.TOPIC_ID
WHERE (FORUM_TOPICS.T_AUTHOR=@mId AND FORUM_REPLY.TOPIC_ID Is Null ) OR (FORUM_TOPICS.T_AUTHOR=@mId AND FORUM_REPLY.TOPIC_ID Not In (SELECT TOPIC_ID FROM FORUM_REPLY WHERE R_AUTHOR=5)) )
AS MY_VIEW
WHERE R_DATE > @startDate
ORDER BY R_DATE DESC;

GO


This creates a stored procedure named pPost, with two parameters: startDate and mId, to allow parameterization of the StartDate for the Posts and of the member Id. Following the keyword As you have the SQL statement, and it finishes with GO.

Pressing OK, will store the stored procedure in the Db.

You can then start Query Analizer, connect to server, select your DB and type:

exec pPost 20010101000000, 5 and you'll get the results you need...

This can also be called from an ASP script, but I guess you know that...

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Aaron S.
Average Member

USA
985 Posts

Posted - 23 April 2002 :  18:59:59  Show Profile  Visit Aaron S.'s Homepage
Thanks, I'll try that.

I also am going to convert some of the default.asp stmts to stored procedures, as I have 54 categories and over 400 forums... so I need all the performance gains I can get.

--Aaron

MySubs Email MOD
MOD to Smile Mgr
HotKeys MOD
Go to Top of Page
Page: of 5 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07