Я подозреваю, что ваша проблема может быть связана с количеством извлекаемых строк.
Короче говоря, число извлеченных строк будет прогрессивным умножением количества совпадающих строк в таблице.
, то есть если состояние is равно x и имеется: -
- 10 строк земли с состоянием x
- 4 строки компании с состоянием x
- 3 строки образования с состоянием x
- 3 строки с состоянием x
- 3 строки отдыха с состоянием x и
- 3 строки погоды с состоянием x
Результатом будет 3240 строк из относительно небольшого объема данных.
Рассмотрим, возможно, более разумный полезный / пригодный для использования объем данных, например: -
- 30 строк земли с состоянием x
- 20 строк компании с состоянием x
- 10 строк образования с состоянием x
- 10 человек строк с состоянием x
- 10 строк отдыха с состоянием x и
- 10 строк погоды с состоянием x
Затем будет сгенерировано 6 000 000 строк, хотя действительно полезные данные могут быть представлены в виде 90 строк
Пример тестирования
Рассмотрим следующее, использованное для имитации вашего запроса:-
DROP TABLE IF EXISTS weather;
DROP TABLE IF EXISTS recreation;
DROP TABLE IF EXISTS people;
DROP TABLE IF EXISTS education;
DROP TABLE IF EXISTS company;
DROP TABLE If EXISTS land;
DROP TABLE IF EXISTS state;
CREATE TABLE IF NOT EXISTS land (landid INTEGER PRIMARY KEY, state_reference INTEGER, state TEXT, state_code TEXT, state_short_code TEXT, land_name TEXT);
CREATE TABLE IF NOT EXISTS company (companyid INTEGER PRIMARY KEY, state_reference INTEGER, state TEXT, company_name TEXT);
CREATE TABLE IF NOT EXISTS education (educationid INTEGER PRIMARY KEY, state_reference INTEGER, state_code TEXT, education_name TEXT);
CREATE TABLE IF NOT EXISTS people (peopleid INTEGER PRIMARY KEY, state_reference INTEGER, state_code TEXT, people_name TEXT);
CREATE TABLE IF NOT EXISTS recreation (recreationid INTEGER PRIMARY KEY, state_reference INTEGER, state_short_code TEXT, recreation_name TEXT);
CREATE TABLE IF NOT EXISTS weather (weatherid INTEGER PRIMARY KEY, state_reference INTEGER, state_short_code TEXT, weather_name TEXT);
-- State Table added to save typing NOTE state_reference was included in all tables to allow state, state_code and state_short_code to be applied automatically (see updates)
CREATE TABLE IF NOT EXISTS state (stateid INTEGER PRIMARY KEY, state_name TEXT UNIQUE, state_code TEXT UNIQUE, state_short_code TEXT UNIQUE );
-- Build the states (20 should be plenty for testing)
INSERT INTO state (state_name, state_code, state_short_code) VALUES
('Alabama','alab','AL'),
('Alaska','alas','AK'),
('Arizona','ariz','AZ'),
('Arkansas','arka','AR'),
('California','cali','CA'),
('Colorado','colo','CO'),
('Connecticut','conn','CT'),
('Delaware','dela','DE'),
('Florida','flor','FL'),
('Georgia','geor','GA'),
('Hawaii','hawa','HI'),
('Idaho','idah','ID'),
('Illinois','illi','IL'),
('Indiana','indi','IN'),
('Iowa','iowa','IA'),
('Kansas','kans','KS'),
('Kentucky','kent','KY'),
('Louisiana','loui','LA'),
('Maine','main','ME'),
('Maryland','mary','MD')
;
-- Insert into the 6 tables randomly generating a state reference
INSERT INTO land (land_name,state_reference) VALUES
('LandA', (SELECT abs(random() % 20) + 1))
,('LandB', (SELECT abs(random() % 20) + 1))
,('LandC', (SELECT abs(random() % 20) + 1))
,('LandD', (SELECT abs(random() % 20) + 1))
,('LandE', (SELECT abs(random() % 20) + 1))
,('LandF', (SELECT abs(random() % 20) + 1))
,('LandG', (SELECT abs(random() % 20) + 1))
,('LandH', (SELECT abs(random() % 20) + 1))
,('LandI', (SELECT abs(random() % 20) + 1))
,('LandJ', (SELECT abs(random() % 20) + 1))
,('LandK', (SELECT abs(random() % 20) + 1))
,('LandL', (SELECT abs(random() % 20) + 1))
,('LandM', (SELECT abs(random() % 20) + 1))
,('LandN', (SELECT abs(random() % 20) + 1))
,('LandO', (SELECT abs(random() % 20) + 1))
,('LandP', (SELECT abs(random() % 20) + 1))
,('LandQ', (SELECT abs(random() % 20) + 1))
,('LandR', (SELECT abs(random() % 20) + 1))
,('LandS', (SELECT abs(random() % 20) + 1))
,('LandT', (SELECT abs(random() % 20) + 1))
,('LandU', (SELECT abs(random() % 20) + 1))
,('LandV', (SELECT abs(random() % 20) + 1))
,('LandW', (SELECT abs(random() % 20) + 1))
,('LandX', (SELECT abs(random() % 20) + 1))
,('LandY', (SELECT abs(random() % 20) + 1))
,('LandZ', (SELECT abs(random() % 20) + 1))
,('Land1', (SELECT abs(random() % 20) + 1))
,('Land2', (SELECT abs(random() % 20) + 1))
,('Land3', (SELECT abs(random() % 20) + 1))
,('Land4', (SELECT abs(random() % 20) + 1))
,('Land5', (SELECT abs(random() % 20) + 1))
,('Land6', (SELECT abs(random() % 20) + 1))
,('Land7', (SELECT abs(random() % 20) + 1))
,('Land8', (SELECT abs(random() % 20) + 1))
,('Land9', (SELECT abs(random() % 20) + 1))
,('Land0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO company (company_name,state_reference) VALUES
('CompA', (SELECT abs(random() % 20) + 1))
,('CompB', (SELECT abs(random() % 20) + 1))
,('CompC', (SELECT abs(random() % 20) + 1))
,('CompD', (SELECT abs(random() % 20) + 1))
,('CompE', (SELECT abs(random() % 20) + 1))
,('CompF', (SELECT abs(random() % 20) + 1))
,('CompG', (SELECT abs(random() % 20) + 1))
,('CompH', (SELECT abs(random() % 20) + 1))
,('CompI', (SELECT abs(random() % 20) + 1))
,('CompJ', (SELECT abs(random() % 20) + 1))
,('CompK', (SELECT abs(random() % 20) + 1))
,('CompL', (SELECT abs(random() % 20) + 1))
,('CompM', (SELECT abs(random() % 20) + 1))
,('CompN', (SELECT abs(random() % 20) + 1))
,('CompO', (SELECT abs(random() % 20) + 1))
,('CompP', (SELECT abs(random() % 20) + 1))
,('CompQ', (SELECT abs(random() % 20) + 1))
,('CompR', (SELECT abs(random() % 20) + 1))
,('CompS', (SELECT abs(random() % 20) + 1))
,('CompT', (SELECT abs(random() % 20) + 1))
,('CompU', (SELECT abs(random() % 20) + 1))
,('CompV', (SELECT abs(random() % 20) + 1))
,('CompW', (SELECT abs(random() % 20) + 1))
,('CompX', (SELECT abs(random() % 20) + 1))
,('CompY', (SELECT abs(random() % 20) + 1))
,('CompZ', (SELECT abs(random() % 20) + 1))
,('Comp1', (SELECT abs(random() % 20) + 1))
,('Comp2', (SELECT abs(random() % 20) + 1))
,('Comp3', (SELECT abs(random() % 20) + 1))
,('Comp4', (SELECT abs(random() % 20) + 1))
,('Comp5', (SELECT abs(random() % 20) + 1))
,('Comp6', (SELECT abs(random() % 20) + 1))
,('Comp7', (SELECT abs(random() % 20) + 1))
,('Comp8', (SELECT abs(random() % 20) + 1))
,('Comp9', (SELECT abs(random() % 20) + 1))
,('Comp0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO education (education_name,state_reference) VALUES
('EducA', (SELECT abs(random() % 20) + 1))
,('EducB', (SELECT abs(random() % 20) + 1))
,('EducC', (SELECT abs(random() % 20) + 1))
,('EducD', (SELECT abs(random() % 20) + 1))
,('EducE', (SELECT abs(random() % 20) + 1))
,('EducF', (SELECT abs(random() % 20) + 1))
,('EducG', (SELECT abs(random() % 20) + 1))
,('EducH', (SELECT abs(random() % 20) + 1))
,('EducI', (SELECT abs(random() % 20) + 1))
,('EducJ', (SELECT abs(random() % 20) + 1))
,('EducK', (SELECT abs(random() % 20) + 1))
,('EducL', (SELECT abs(random() % 20) + 1))
,('EducM', (SELECT abs(random() % 20) + 1))
,('EducN', (SELECT abs(random() % 20) + 1))
,('EducO', (SELECT abs(random() % 20) + 1))
,('EducP', (SELECT abs(random() % 20) + 1))
,('EducQ', (SELECT abs(random() % 20) + 1))
,('EducR', (SELECT abs(random() % 20) + 1))
,('EducS', (SELECT abs(random() % 20) + 1))
,('EducT', (SELECT abs(random() % 20) + 1))
,('EducU', (SELECT abs(random() % 20) + 1))
,('EducV', (SELECT abs(random() % 20) + 1))
,('EducW', (SELECT abs(random() % 20) + 1))
,('EducX', (SELECT abs(random() % 20) + 1))
,('EducY', (SELECT abs(random() % 20) + 1))
,('EducZ', (SELECT abs(random() % 20) + 1))
,('Educ1', (SELECT abs(random() % 20) + 1))
,('Educ2', (SELECT abs(random() % 20) + 1))
,('Educ3', (SELECT abs(random() % 20) + 1))
,('Educ4', (SELECT abs(random() % 20) + 1))
,('Educ5', (SELECT abs(random() % 20) + 1))
,('Educ6', (SELECT abs(random() % 20) + 1))
,('Educ7', (SELECT abs(random() % 20) + 1))
,('Educ8', (SELECT abs(random() % 20) + 1))
,('Educ9', (SELECT abs(random() % 20) + 1))
,('Educ0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO education (education_name,state_reference) VALUES
('EducA', (SELECT abs(random() % 20) + 1))
,('EducB', (SELECT abs(random() % 20) + 1))
,('EducC', (SELECT abs(random() % 20) + 1))
,('EducD', (SELECT abs(random() % 20) + 1))
,('EducE', (SELECT abs(random() % 20) + 1))
,('EducF', (SELECT abs(random() % 20) + 1))
,('EducG', (SELECT abs(random() % 20) + 1))
,('EducH', (SELECT abs(random() % 20) + 1))
,('EducI', (SELECT abs(random() % 20) + 1))
,('EducJ', (SELECT abs(random() % 20) + 1))
,('EducK', (SELECT abs(random() % 20) + 1))
,('EducL', (SELECT abs(random() % 20) + 1))
,('EducM', (SELECT abs(random() % 20) + 1))
,('EducN', (SELECT abs(random() % 20) + 1))
,('EducO', (SELECT abs(random() % 20) + 1))
,('EducP', (SELECT abs(random() % 20) + 1))
,('EducQ', (SELECT abs(random() % 20) + 1))
,('EducR', (SELECT abs(random() % 20) + 1))
,('EducS', (SELECT abs(random() % 20) + 1))
,('EducT', (SELECT abs(random() % 20) + 1))
,('EducU', (SELECT abs(random() % 20) + 1))
,('EducV', (SELECT abs(random() % 20) + 1))
,('EducW', (SELECT abs(random() % 20) + 1))
,('EducX', (SELECT abs(random() % 20) + 1))
,('EducY', (SELECT abs(random() % 20) + 1))
,('EducZ', (SELECT abs(random() % 20) + 1))
,('Educ1', (SELECT abs(random() % 20) + 1))
,('Educ2', (SELECT abs(random() % 20) + 1))
,('Educ3', (SELECT abs(random() % 20) + 1))
,('Educ4', (SELECT abs(random() % 20) + 1))
,('Educ5', (SELECT abs(random() % 20) + 1))
,('Educ6', (SELECT abs(random() % 20) + 1))
,('Educ7', (SELECT abs(random() % 20) + 1))
,('Educ8', (SELECT abs(random() % 20) + 1))
,('Educ9', (SELECT abs(random() % 20) + 1))
,('Educ0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO people (people_name,state_reference) VALUES
('ppplA', (SELECT abs(random() % 20) + 1))
,('ppplB', (SELECT abs(random() % 20) + 1))
,('ppplC', (SELECT abs(random() % 20) + 1))
,('ppplD', (SELECT abs(random() % 20) + 1))
,('ppplE', (SELECT abs(random() % 20) + 1))
,('ppplF', (SELECT abs(random() % 20) + 1))
,('ppplG', (SELECT abs(random() % 20) + 1))
,('ppplH', (SELECT abs(random() % 20) + 1))
,('ppplI', (SELECT abs(random() % 20) + 1))
,('ppplJ', (SELECT abs(random() % 20) + 1))
,('ppplK', (SELECT abs(random() % 20) + 1))
,('ppplL', (SELECT abs(random() % 20) + 1))
,('ppplM', (SELECT abs(random() % 20) + 1))
,('ppplN', (SELECT abs(random() % 20) + 1))
,('ppplO', (SELECT abs(random() % 20) + 1))
,('ppplP', (SELECT abs(random() % 20) + 1))
,('ppplQ', (SELECT abs(random() % 20) + 1))
,('ppplR', (SELECT abs(random() % 20) + 1))
,('ppplS', (SELECT abs(random() % 20) + 1))
,('ppplT', (SELECT abs(random() % 20) + 1))
,('ppplU', (SELECT abs(random() % 20) + 1))
,('ppplV', (SELECT abs(random() % 20) + 1))
,('ppplW', (SELECT abs(random() % 20) + 1))
,('ppplX', (SELECT abs(random() % 20) + 1))
,('ppplY', (SELECT abs(random() % 20) + 1))
,('ppplZ', (SELECT abs(random() % 20) + 1))
,('pppl1', (SELECT abs(random() % 20) + 1))
,('pppl2', (SELECT abs(random() % 20) + 1))
,('pppl3', (SELECT abs(random() % 20) + 1))
,('pppl4', (SELECT abs(random() % 20) + 1))
,('pppl5', (SELECT abs(random() % 20) + 1))
,('pppl6', (SELECT abs(random() % 20) + 1))
,('pppl7', (SELECT abs(random() % 20) + 1))
,('pppl8', (SELECT abs(random() % 20) + 1))
,('pppl9', (SELECT abs(random() % 20) + 1))
,('pppl0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO recreation (recreation_name,state_reference) VALUES
('recrA', (SELECT abs(random() % 20) + 1))
,('recrB', (SELECT abs(random() % 20) + 1))
,('recrC', (SELECT abs(random() % 20) + 1))
,('recrD', (SELECT abs(random() % 20) + 1))
,('recrE', (SELECT abs(random() % 20) + 1))
,('recrF', (SELECT abs(random() % 20) + 1))
,('recrG', (SELECT abs(random() % 20) + 1))
,('recrH', (SELECT abs(random() % 20) + 1))
,('recrI', (SELECT abs(random() % 20) + 1))
,('recrJ', (SELECT abs(random() % 20) + 1))
,('recrK', (SELECT abs(random() % 20) + 1))
,('recrL', (SELECT abs(random() % 20) + 1))
,('recrM', (SELECT abs(random() % 20) + 1))
,('recrN', (SELECT abs(random() % 20) + 1))
,('recrO', (SELECT abs(random() % 20) + 1))
,('recrP', (SELECT abs(random() % 20) + 1))
,('recrQ', (SELECT abs(random() % 20) + 1))
,('recrR', (SELECT abs(random() % 20) + 1))
,('recrS', (SELECT abs(random() % 20) + 1))
,('recrT', (SELECT abs(random() % 20) + 1))
,('recrU', (SELECT abs(random() % 20) + 1))
,('recrV', (SELECT abs(random() % 20) + 1))
,('recrW', (SELECT abs(random() % 20) + 1))
,('recrX', (SELECT abs(random() % 20) + 1))
,('recrY', (SELECT abs(random() % 20) + 1))
,('recrZ', (SELECT abs(random() % 20) + 1))
,('recr1', (SELECT abs(random() % 20) + 1))
,('recr2', (SELECT abs(random() % 20) + 1))
,('recr3', (SELECT abs(random() % 20) + 1))
,('recr4', (SELECT abs(random() % 20) + 1))
,('recr5', (SELECT abs(random() % 20) + 1))
,('recr6', (SELECT abs(random() % 20) + 1))
,('recr7', (SELECT abs(random() % 20) + 1))
,('recr8', (SELECT abs(random() % 20) + 1))
,('recr9', (SELECT abs(random() % 20) + 1))
,('recr0', (SELECT abs(random() % 20) + 1))
;
INSERT INTO weather (weather_name,state_reference) VALUES
('WthrA', (SELECT abs(random() % 20) + 1))
,('WthrB', (SELECT abs(random() % 20) + 1))
,('WthrC', (SELECT abs(random() % 20) + 1))
,('WthrD', (SELECT abs(random() % 20) + 1))
,('WthrE', (SELECT abs(random() % 20) + 1))
,('WthrF', (SELECT abs(random() % 20) + 1))
,('WthrG', (SELECT abs(random() % 20) + 1))
,('WthrH', (SELECT abs(random() % 20) + 1))
,('WthrI', (SELECT abs(random() % 20) + 1))
,('WthrJ', (SELECT abs(random() % 20) + 1))
,('WthrK', (SELECT abs(random() % 20) + 1))
,('WthrL', (SELECT abs(random() % 20) + 1))
,('WthrM', (SELECT abs(random() % 20) + 1))
,('WthrN', (SELECT abs(random() % 20) + 1))
,('WthrO', (SELECT abs(random() % 20) + 1))
,('WthrP', (SELECT abs(random() % 20) + 1))
,('WthrQ', (SELECT abs(random() % 20) + 1))
,('WthrR', (SELECT abs(random() % 20) + 1))
,('WthrS', (SELECT abs(random() % 20) + 1))
,('WthrT', (SELECT abs(random() % 20) + 1))
,('WthrU', (SELECT abs(random() % 20) + 1))
,('WthrV', (SELECT abs(random() % 20) + 1))
,('WthrW', (SELECT abs(random() % 20) + 1))
,('WthrX', (SELECT abs(random() % 20) + 1))
,('WthrY', (SELECT abs(random() % 20) + 1))
,('WthrZ', (SELECT abs(random() % 20) + 1))
,('Wthr1', (SELECT abs(random() % 20) + 1))
,('Wthr2', (SELECT abs(random() % 20) + 1))
,('Wthr3', (SELECT abs(random() % 20) + 1))
,('Wthr4', (SELECT abs(random() % 20) + 1))
,('Wthr5', (SELECT abs(random() % 20) + 1))
,('Wthr6', (SELECT abs(random() % 20) + 1))
,('Wthr7', (SELECT abs(random() % 20) + 1))
,('Wthr8', (SELECT abs(random() % 20) + 1))
,('Wthr9', (SELECT abs(random() % 20) + 1))
,('Wthr0', (SELECT abs(random() % 20) + 1))
;
-- Update the tables to apply the text for the state, state_code and state_short_code
UPDATE land SET
state = (SELECT state_name FROM state WHERE stateid = state_reference),
state_code = (SELECT state_code FROM state WHERE stateid = state_reference),
state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;
UPDATE company SET
state = (SELECT state_name FROM state WHERE stateid = state_reference)
;
UPDATE education SET
state_code = (SELECT state_code FROM state WHERE stateid = state_reference)
;
UPDATE people SET
state_code = (SELECT state_code FROM state WHERE stateid = state_reference)
;
UPDATE recreation SET
state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;
UPDATE weather SET
state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;
-- Just in case the tables need to be checked
SELECT * FROM land ;
SELECT * FROM company;
SELECT * FROM education;
SELECT * FROM people;
SELECT * FROM recreation;
SELECT * FROM weather;
-- Now try the query as per the question (well close to it)
-- EXPLAIN QUERY PLAN
SELECT *
FROM
land,company, education, people, recreation, weather
WHERE upper(land.state)= upper('Maine')
AND land.State=company.State
AND land.State_code=education.State_code
AND land.State_code=people.State_code
AND land.State_short_code=recreation.State_short_code
AND land.State_short_code=weather.State_short_code
;
-- Calculate the permutations
WITH counts AS ( SELECT
(SELECT count() FROM land WHERE upper(state) = upper('Maine')) AS landcount ,
(SELECT count() FROM company WHERE upper(state) = upper('Maine')) AS companycount,
(SELECT count() FROM education WHERE upper(state_code) = upper('main')) AS educationcount,
(SELECT count() FROM people WHERE upper(state_code) = upper('main')) AS peoplecount,
(SELECT count() FROM recreation WHERE upper(state_short_code) = upper('ME')) AS recreationcount,
(SELECT count() FROM weather WHERE upper(state_short_code) = upper('ME')) AS weathercount
)
SELECT *, (landcount * companycount * educationcount * peoplecount * recreationcount * weathercount) AS permutations FROM counts;
Результаты
При выполнении вышеизложенного получено от 0 до более 1000 строк (относительно низкий риск создания строк для Мэна (PS НЕ удаляйте предложение WHERE, попытка будетсделано для генерации 2 176 782 336 строк (пробовал это через 10 минут, и мне пришлось перезагружать компьютер))).
Чаще всего будет 0 строк, соответствующих всем критериям.Однако вот результаты прогона, который дал 90 строк: -
Первые перестановки (последний запрос): -
Некоторые из результирующих данных, которые, как вы можете видеть, скорее всего, будут раздражать, когда получат любое разумное количество данных: -