Może możesz mi pomóc. Muszę zapytać o 3 tabele, aby uzyskać dane dla zasobów finansowych.Proste zapytanie MySQL trwające wiecznie (ponad 20 minut!)
Chodzi o to, aby przejść do tabeli instrumentów, znaleźć indeks dla każdego instrumentu, a następnie wprowadzić wszystkie ceny dla danego instrumentu wraz ze wskaźnikami znajdującymi się w osobnej tabeli.
Tabele stockdata
i indicators
to prawie 50 000 rekordów. instruments
tylko 30.
To jest zapytanie, które nie działa:
SELECT
indicators.ddate,
instruments.name,
indicators.sma_14,
indicators.sma_5,
stockdata.close
FROM
indicators
INNER JOIN instruments ON (indicators.instrument_id=instruments.id)
INNER JOIN stockdata ON (instruments.name=stockdata.name)
Oto EXPLAIN wynik
+----+-------------+-------------+-------+-----------------------------+---------------------+---------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra |
+----+-------------+-------------+-------+-----------------------------+---------------------+---------+------+-------------+
| 1 | SIMPLE | instruments | index | PRIMARY,instruments_index01 | instruments_index01 | 61 | 25 | Using index |
| 1 | SIMPLE | indicators | ref | indicators_index01 | indicators_index01 | 5 | 973 | Using where |
| 1 | SIMPLE | stockdata | ref | stockdata_index01 | stockdata_index01 | 31 | 1499 | Using where |
+----+-------------+-------------+-------+-----------------------------+---------------------+---------+------+-------------+
naprawdę wdzięczni za każdą pomoc można zapewnić!
Jest to schemat dla części tabel, które są zaangażowane w moje pytanie:
TABLE `indicators` (
`id` int AUTO_INCREMENT NOT NULL,<br>
`instrument_id` int,
`date` date,
`sma_5` float(10,3),
`sma_14` float(10,3),
`ema_14` float(10,3),
/* Keys */
PRIMARY KEY (`id`)
)
TABLE `instruments` (
`id` int AUTO_INCREMENT NOT NULL,
`name` char(20),
`country` char(50),
`newsquery` char(100),
/* Keys */
PRIMARY KEY (`id`)
)
TABLE `stockdata` (
`id` int AUTO_INCREMENT NOT NULL,
`name` char(10),
`date` date,
`open` float,
`high` float,
`low` float,
`close` float,
`volume` int,
`adjclose` float,
/* Keys */
PRIMARY KEY (`id`)
)
Dlaczego są nawiasy wokół warunku łączenia? – Fosco
Ile wierszy znajduje się w każdej z tabel? – sgriffinusa
Witaj, tabele akcji i wskaźników to prawie 50 000 rekordów. Instrumenty tylko 30. – JordanBelf