AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / dba / Perguntas / 20079
Accepted
newbie14
newbie14
Asked: 2012-06-28 15:21:59 +0800 CST2012-06-28 15:21:59 +0800 CST 2012-06-28 15:21:59 +0800 CST

Guia de partições multitabelas

  • 772

Temos uma tabela principal chamada tblLink nela terá um campo de data. O tblLink terá sua chave primária como estrangeira em algumas outras tabelas também e uma das tabelas tblMainData que com o tempo ficará em milhões de linhas. Portanto, gostaríamos de manter apenas 3 meses de dados. O resto gostaríamos de limpar e mantê-lo para gerar relatórios de histórico. O problema em todo o Google apenas fala sobre uma única partição de tabela, mas nunca falou sobre partição de várias tabelas. Então, como resolver meu problema abaixo estão a tabela de criação e as consultas de amostra também.

Some of the queries. 
Query 1 

SELECT DISTINCT tblLocationFrom.geoFenceName As locationFrom, tblLocationTo.geoFenceName As locationTo, 
tblLink.linkID,CAST(Date_Add(tblLink.dateTimeStartJourney, Interval '".$gmtValue."' hour_minute) AS CHAR) As dateTimeStartJourney,  
CAST(Date_Add(tblLink.dateTimeEndJourney, Interval '".$gmtValue."' hour_minute) AS CHAR) As dateTimeEndJourney1,CAST(Date_Add(CAST(Date_Add(tblLink.dateTimeEnd, Interval '-08:00' hour_minute) AS CHAR) , Interval '".$gmtValue."' hour_minute) AS CHAR) As dateTimeEndJourney2, 
FROM tblLink 
JOIN tblGeoFence AS tblLocationFrom ON tblLink.locationFromID = tblLocationFrom.geoFenceID 
JOIN tblGeoFence AS tblLocationTo ON tblLink.locationToID = tblLocationTo.geoFenceID 
WHERE (dateTimeStartJourney between '".$b. "' And '".$e."' And tblLink.compID=$cID 

Query 2 

SELECT tblGeoFence.geoFenceName,     CAST(Date_Add(tblEventAlert.eventAlertDateTime , Interval '".$gmtValue."' hour_minute) AS CHAR) As eventAlertDateTime 
FROM tblEventAlert 
LEFT JOIN tblGeoFence ON tblEventAlert.geoFenceID=tblGeoFence.geoFenceID 
WHERE tblEventAlert.link=".$lID." Order By tblEventAlert.eventAlertDateTime Asc"; 

Create table statements. 

CREATE TABLE IF NOT EXISTS `tblLink` ( 
`linkID` int(5) NOT NULL, 
`compID` int(5) NOT NULL, 
`vehicleID` int(5) NOT NULL, 
`deviceID` int(5) NOT NULL, 
`locationFromID` int(5) NOT NULL, 
`locationToID` int(5) NOT NULL, 
`employeeIDInsert` int(5) NOT NULL, 
`dateTimeInsert` datetime NOT NULL, 
`dateTimeStartJourney` datetime NOT NULL, 
`dateTimeEnd` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 
`dateTimeEndJourney` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 
`linkStatus` enum('a','d','e','m') NOT NULL, 
PRIMARY KEY (`linkID`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 


CREATE TABLE IF NOT EXISTS `tblEmailLog` ( 
`emailLogID` int(11) NOT NULL AUTO_INCREMENT, 
`compID` smallint(6) NOT NULL, 
`linkID` int(11) NOT NULL DEFAULT '0', 
`userID` smallint(6) NOT NULL, 
`alertCodeID` tinyint(4) NOT NULL, 
`eventAlertID` int(11) NOT NULL, 
`userEmail` varchar(100) NOT NULL, 
`alertDateTime` datetime NOT NULL, 
`alertInsertDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
PRIMARY KEY (`emailLogID`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 


CREATE TABLE IF NOT EXISTS `tblEventAlert` ( 
`eventAlertID` int(11) NOT NULL AUTO_INCREMENT, 
`compID` int(5) NOT NULL, 
`linkID` int(11) NOT NULL DEFAULT '0', 
`mainDataID` int(5) NOT NULL, 
`vehicleID` int(5) NOT NULL, 
`geoFenceID` int(5) NOT NULL, 
`eventAlertDateTime` datetime NOT NULL, 
`eventAlertSentEmail` varchar(50) DEFAULT NULL, 
`eventAlertMessage` varchar(255) NOT NULL, 
PRIMARY KEY (`eventAlertID`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 



CREATE TABLE IF NOT EXISTS `tblMainData` ( 
`mainDataID` int(11) NOT NULL AUTO_INCREMENT, 
`linkID` int(5) NOT NULL, 
`header` varchar(3) NOT NULL, 
`deviceSerialNumber` varchar(20) NOT NULL, 
`latitude` double NOT NULL, 
`longitude` double NOT NULL, 
`speed` float NOT NULL, 
`course` int(3) NOT NULL, 
`dateTimer` datetime NOT NULL, 
`gpsDateTime` datetime NOT NULL, 
`insertDateTime` datetime NOT NULL, 
`odoMeter` float NOT NULL DEFAULT '0', 
`driverID` int(5) NOT NULL, 
`eventAlertID` int(11) NOT NULL DEFAULT '0', 
`mainDataInsertDateTime` datetime NOT NULL, 
`gpsString` varchar(450) NOT NULL, 
PRIMARY KEY (`mainDataID`), 
KEY `dateTime` (`dateTimer`), 
KEY `linkID` (`linkID`), 
KEY `eventAlertID` (`eventAlertID`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 


CREATE TABLE IF NOT EXISTS `tblSubData` ( 
`subDataID` int(11) NOT NULL AUTO_INCREMENT, 
`mainDataID` int(11) NOT NULL, 
`linkID` int(11) NOT NULL, 
`eventAlertID` int(11) NOT NULL, 
`deviceSerialNumber` varchar(20) NOT NULL, 
`subdeviceSerialNumber` varchar(20) NOT NULL, 
`dateTimer` datetime NOT NULL, 
`eventType` varchar(2) NOT NULL 
PRIMARY KEY (`subDataID`), 
KEY `mainDataID` (`mainDataID`), 
KEY `linkID` (`linkID`), 
KEY `eventAlertID` (`eventAlertID`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
mysql partitioning
  • 1 1 respostas
  • 121 Views

1 respostas

  • Voted
  1. Best Answer
    Rick James
    2012-06-30T13:27:45+08:002012-06-30T13:27:45+08:00

    O que você quer dizer com "partição multitable"? Você pode particionar cada tabela independentemente.

    INT(3) não significa o que você pode pensar.

    Saiba mais sobre índices "compostos".

    • 1

relate perguntas

  • Existem ferramentas de benchmarking do MySQL? [fechado]

  • Onde posso encontrar o log lento do mysql?

  • Como posso otimizar um mysqldump de um banco de dados grande?

  • Quando é o momento certo para usar o MariaDB em vez do MySQL e por quê?

  • Como um grupo pode rastrear alterações no esquema do banco de dados?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Como ver a lista de bancos de dados no Oracle?

    • 8 respostas
  • Marko Smith

    Quão grande deve ser o mysql innodb_buffer_pool_size?

    • 4 respostas
  • Marko Smith

    Listar todas as colunas de uma tabela especificada

    • 5 respostas
  • Marko Smith

    restaurar a tabela do arquivo .frm e .ibd?

    • 10 respostas
  • Marko Smith

    Como usar o sqlplus para se conectar a um banco de dados Oracle localizado em outro host sem modificar meu próprio tnsnames.ora

    • 4 respostas
  • Marko Smith

    Como você mysqldump tabela (s) específica (s)?

    • 4 respostas
  • Marko Smith

    Como selecionar a primeira linha de cada grupo?

    • 6 respostas
  • Marko Smith

    Listar os privilégios do banco de dados usando o psql

    • 10 respostas
  • Marko Smith

    Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Como faço para listar todos os bancos de dados e tabelas usando o psql?

    • 7 respostas
  • Martin Hope
    Mike Walsh Por que o log de transações continua crescendo ou fica sem espaço? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland Listar todas as colunas de uma tabela especificada 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney O MySQL pode realizar consultas razoavelmente em bilhões de linhas? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx Como posso monitorar o andamento de uma importação de um arquivo .sql grande? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison Como você mysqldump tabela (s) específica (s)? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta Listar os privilégios do banco de dados usando o psql 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas Como posso cronometrar consultas SQL usando psql? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas Como faço para listar todos os bancos de dados e tabelas usando o psql? 2011-02-18 00:45:49 +0800 CST
  • Martin Hope
    bernd_k Quando devo usar uma restrição exclusiva em vez de um índice exclusivo? 2011-01-05 02:32:27 +0800 CST

Hot tag

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve