SELECT pairs.pair_id, pairs.binance AS exchange_interval_symbol, candles_grouped.candle_interval_id, candles_grouped.last_candle_open_time, candle_interval_period.binance AS exchange_interval_name, candle_interval_period.candle_interval_time, candles.candle_last_end FROM trading.pairs JOIN trading.candle_interval_period LEFT JOIN (SELECT candles.candle_pair_id, candles.candle_interval_id, MAX(candle_open_time) AS last_candle_open_time FROM trading.candles FORCE INDEX (CANDLE_EXCHANGE_UNIQUE) WHERE candles.candle_exchange_id = 1 GROUP BY candles.candle_pair_id , candles.candle_interval_id) candles_grouped ON pairs.pair_id = candles_grouped.candle_pair_id AND candle_interval_period.candle_interval_id = candles_grouped.candle_interval_id LEFT JOIN trading.candles ON candles.candle_pair_id = candles_grouped.candle_pair_id AND candles.candle_interval_id = candles_grouped.candle_interval_id AND candles.candle_exchange_id = 1 AND candles.candle_open_time = candles_grouped.last_candle_open_time
Была такая мысль, но в итоге перебор индекса принудительный решил вопрос
Обсуждают сегодня