2017-09-26 9 views
0

es ist das erste Mal, eine gespeicherte Prozedur in mysql zu erstellen.Fehlercode: 1172. Ergebnis bestand aus mehr als einer Zeile [MySQL]

Was sie tut, ist,

first- get count of all records 

second- loop through that table 1 by 1 

third- compare each entry if it is a duplicate 

fourth- insert duplicate in a temporary table 

last- display duplicates 

Es funktioniert einwandfrei auf 100-200 Einträge BUT auf größere Datensätze bis zu 500+ (manchmal 25k) wirft eine Nachricht

Fehler Code: 1172. Ergebnis bestand aus mehr als einer Zeile

Ich habe dieses Problem gegooglet, aber keiner von ihnen (Antworten) hilft mir um mein Problem zu lösen.

Bitte nehmen Sie sich einen Blick auf mein Skript

BEGIN 

DECLARE n INT DEFAULT 0; 
DECLARE i INT DEFAULT 0; 

DECLARE i_sku VARCHAR(255); 
DECLARE i_concatenated_attributes MEDIUMTEXT; 

DECLARE f_sku VARCHAR(255); 
DECLARE f_offer_type VARCHAR(255); 
DECLARE f_name VARCHAR(255); 
DECLARE f_product_owner VARCHAR(255); 
DECLARE f_listing_city VARCHAR(255); 
DECLARE f_listing_area VARCHAR(255); 
DECLARE f_price DOUBLE; 
DECLARE f_bedrooms INT; 
DECLARE f_building_size INT; 
DECLARE f_land_size INT; 
DECLARE f_concatenated_attributes MEDIUMTEXT; 
DECLARE f_duplicate_percentage INT; 

SELECT COUNT(*) FROM unit_temp_listing INTO n; 
CREATE TEMPORARY TABLE IF NOT EXISTS temp_temp (dup_sku VARCHAR(255), dup_percentage INT, attribs MEDIUMTEXT); 
SET i=0; 
WHILE i<n DO 
    -- Get all unit listings (one by one) 
    SELECT 
    sku, concat_ws(',',offer_type,name,product_owner,listing_city,listing_area,price,ifnull(bedrooms,0),ifnull(building_size,0),ifnull(land_size,0)) as concatenated_attributes 
INTO i_sku, i_concatenated_attributes 
FROM unit_temp_listing 
limit 1 offset i; 
-- Compare one by one (sadla) 
SELECT 
    f.sku, f.offer_type, f.name, f.product_owner, f.listing_city, f.listing_area, f.price, f.bedrooms, f.building_size, f.land_size, 
    levenshtein_ratio(concat_ws(',',f.offer_type,f.name,f.product_owner,f.listing_city,f.listing_area,f.price,ifnull(f.bedrooms,0),ifnull(f.building_size,0),ifnull(f.land_size,0)),i_concatenated_attributes) as f_duplicate_percentage, 
    concat_ws(',',f.offer_type,f.name,f.product_owner,f.listing_city,f.listing_area,f.price,ifnull(f.bedrooms,0),ifnull(f.building_size,0),ifnull(f.land_size,0)) as fconcatenated_attributes 
INTO f_sku, f_offer_type, f_name, f_product_owner, f_listing_city, f_listing_area, f_price, f_bedrooms, f_building_size, f_land_size, f_duplicate_percentage, f_concatenated_attributes 
FROM unit_temp_listing f 
WHERE substring(soundex(concat_ws(',',offer_type,name,product_owner,listing_city,listing_area,price,ifnull(bedrooms,0),ifnull(building_size,0),ifnull(land_size,0))),1,10) = substring(soundex(i_concatenated_attributes),1,10) 
    AND levenshtein_ratio(concat_ws(',',offer_type,name,product_owner,listing_city,listing_area,price,ifnull(bedrooms,0),ifnull(building_size,0),ifnull(land_size,0)),i_concatenated_attributes) > 90 
    AND f.sku != i_sku; 
-- INSERT duplicates 
IF(f_sku IS NOT NULL) THEN 
    INSERT INTO temp_temp (dup_sku, dup_percentage, attribs) VALUES (f_sku, f_duplicate_percentage, f_concatenated_attributes); 
    SET f_sku = null; 
    SET f_duplicate_percentage = null; 
    SET f_concatenated_attributes = null; 
END IF; 
SET i = i + 1; 
END WHILE; 
SELECT * FROM temp_temp; 
DROP TABLE temp_temp; 
End 

Was ist das Problem?

Antwort

0

Hallo zu meinen Kollegen Entwickler da draußen Ich habe bereits mein Problem gelöst und ich möchte es hier teilen.

Das Problem war, meine SECONDSELECT Anweisung innerhalb der WHILE Schleife war mehrere Zeilen zurückgeben. Ich habe versucht, CURSOR, aber ich habe immer noch die Fehlermeldung. Also habe ich versucht, in der INSERT Aussage wie diese

INSERT INTO table_name (columns, ...) SELECT_STATEMENT 

dass zweite SELECT Aussage von mir zu setzen und dann wurde Problem gelöst! Aber wenn hier jemand eine Idee hat, meine Anfrage zu optimieren, dann helft mir bitte. Ich muss 20k + Datensätze verarbeiten, aber wegen der Zeit der Ausführung dauerte zu lange, ich begnüge mich nur für 500 für 15-20 Minuten.

Vielen Dank für die 18 Ansichten (zum Zeitpunkt des Schreibens).

Glückliche Codierung!

Verwandte Themen