hej på er
jag underhåller ett gammalt system på våra servrar där man får tillgång till produkter man abonnerar på, detta genom att slå samman några tabeller med union till en vy, som jag sen joinar med en tabell på ett värde... ganska meckigt men det funkar hyfsat och skall bara leva några månader till (icke detomindre måste det ju fungera...)
det aktuella dbcaset är SQL 7.0
vy ett ser ut såhär i koden:
SELECT Typ = 1, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_ISO where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
--ca 19000 poster
UNION
SELECT Typ = 2, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_IEC where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
-- ca 30 000 poster
UNION
SELECT Typ = 3, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_SS where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
-- ca 33 000 poster
UNION
SELECT Typ = 4, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_DIN_Avtal where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
-- ca 1400 poster
UNION
SELECT Typ = 5, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_ANSI where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
--ca 34 000 poster
UNION
SELECT Typ = 6, Dokid,pages, Description, Edition,
Title = Cast(Title AS varchar(255)), For_Title, Doc_Type,
Pub_Date, sek_Price,eur_price, Number, Ann_Date,
pdf_name,pdf_size
FROM Catalog_Online_ISOIEC where (doc_type in (1,2,3,20,96,99) AND pub_date is not null)
--ca 2000 poster
jag har index på fälten dokid, description samt på doc_type/pubdate (dessa två i samma index).
Jag typar för att man skall få tillgång till de olika typer av std mha kryssrutor i sökningen senare. select * from ... where type in(1,2,5) t ex
då man vill lista totala antalet produkter hos en specifik kund använder man sig av en annan vy:
SELECT a.CustomerID,
b.Typ,
b.pages,
b.Description,
b.Edition,
b.Title,
b.For_Title,
b.Pub_Date,
b.Ann_Date,
b.pdf_name,
b.pdf_size,
a.GroupID,
b.Dokid,
b.sek_price,
b.eur_price
FROM Cust_Subscr_Ref a, vy_skapad_med_ovanstående_union b
WHERE a.DokID = b.Dokid
som en inner join alltså...
på sidan skickar jag sedan in selectsatsen med tillägget: and customerid = kundid
detta ger en lista, men i nuläget tar den ibland över 20 sekunder att köra...
ser ni att jag kan trimma denna något utan att mecka med själva tabellstrukturen, gärna ideer på index (det är faktiskt de som tunin wizarden föreslår) typ vad det bör vara för typer, skall de vara separata etc... kan man lösa det utan att köra jätteUNION eller vad säger ni som brukar vara duktiga på sådant här?
mvh
Hoppis
red: felformulerat

