Author |
Topic |
fametown
Starting Member
4 Posts |
Posted - 2006-12-19 : 13:17:38
|
Hi!I'm a spanish webdeveloper that make the website www.fametown.com, with a bigger pictures galleries. I have a big problem in my SQL query that show the pictures... it need more than 20 seconds to complete. I found that here: "(F.IdPersonaje = 233) OR (F.IdPersonaje = 234)" its the problem. If i only select one F.IdPersonaje the query it's very very fast. But if i add OR... OR... OR... it's very slow. Can i use any alternative???The website of this query is: http://www.fametown.com/sp/fotos.aspx?carpeta=victoriaadams&grp=5&debug=trueTHANKS A LOT !!!SELECT F.Id, C.Nick, F.Cpe, F.IdColaborador, F.Vistas, F.Nombre, F.Ruta, F.Ancho, F.Alto, F.Peso, F.Fecha, F.Puntos, F.NumVotos, P.Nombre As NombrePersonaje FROM Fotos F, Usuarios C, Personajes P WHERE F.Cpe < 60 AND ((F.IdPersonaje = 233) OR (F.IdPersonaje = 234)) AND F.IdColaborador = C.Id AND F.IdPersonaje = P.Id AND F.Id IN (SELECT TOP 1000 F.Id FROM Fotos F, Usuarios C, Personajes P WHERE F.Cpe < 60 AND ((F.IdPersonaje = 233) OR (F.IdPersonaje = 234)) AND F.IdColaborador = C.Id AND F.IdPersonaje = P.Id AND F.Id NOT IN (SELECT TOP 0 F.Id FROM Fotos F, Usuarios C, Personajes P WHERE F.Cpe < 60 AND ((F.IdPersonaje = 233) OR (F.IdPersonaje = 234)) AND F.IdColaborador = C.Id AND F.IdPersonaje = P.Id ORDER BY F.Fecha DESC, F.Nombre DESC, F.Id DESC) ORDER BY F.Fecha DESC, F.Nombre DESC, F.Id DESC) ORDER BY F.Fecha DESC, F.Nombre DESC, F.Id DESC |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-19 : 13:28:59
|
Try thisSELECT TOP 1000 f.Id, c.Nick, f.Cpe, f.IdColaborador, f.Vistas, f.Nombre, f.Ruta, f.Ancho, f.Alto, f.Peso, f.Fecha, f.Puntos, f.NumVotos, p.Nombre As NombrePersonajeFROM Fotos AS fINNER JOIN Usuarios AS c ON c.Id = f.IdColaboradorINNER JOIN Personajes AS p ON p.Id = f.IdPersonajeWHERE f.Cpe < 60 AND f.IdPersonaje IN (233, 234)ORDER BY f.Fecha DESC, f.Nombre DESC, f.Id DESC Peter LarssonHelsingborg, Sweden |
 |
|
fametown
Starting Member
4 Posts |
Posted - 2006-12-19 : 16:10:05
|
This query run fast... but i need to do a script that can "paginate" the records. If i select 20 pictures in each page i need a query that take "1 to 20", "20 to 40", "40 to 60".... Can you make this mod in your query. THANKS!!! |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-19 : 23:39:22
|
http://weblogs.sqlteam.com/jeffs/archive/2004/03/22/1085.aspxMadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-20 : 04:24:31
|
[code]declare @stage table ( rowid smallint identity(0, 1), id ..., nick ..., cpe ..., idcolaborador ..., vistas ..., nombre ..., ruta ..., ancho ..., alto ..., peso ..., fecha ..., puntos ..., numvotos ..., nombrepersonaje ... )insert @stage ( id, nick, cpe, idcolaborador, vistas, nombre, ruta, ancho, alto, peso, fecha, puntos, numvotos, nombrepersonaje )SELECT TOP 1000 f.Id, c.Nick, f.Cpe, f.IdColaborador, f.Vistas, f.Nombre, f.Ruta, f.Ancho, f.Alto, f.Peso, f.Fecha, f.Puntos, f.NumVotos, p.NombreFROM Fotos AS fINNER JOIN Usuarios AS c ON c.Id = f.IdColaboradorINNER JOIN Personajes AS p ON p.Id = f.IdPersonajeWHERE f.Cpe < 60 AND f.IdPersonaje IN (233, 234)ORDER BY f.Fecha DESC, f.Nombre DESC, f.Id DESCSELECT Id, Nick, Cpe, IdColaborador, Vistas, Nombre, Ruta, Ancho, Alto, Peso, Fecha, Puntos, NumVotos, NombrePersonajeFROM @StageWHERE RowID / 20 = <YourPageNumberHere>ORDER BY RowID[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|