sql-optimization

MySQL: How to find leaves in specific node

强颜欢笑 提交于 2019-11-28 10:34:31
I know this kind questions has been posted here many times, for exmaple: Java way I have huge amount of data (150k+) in standard tree pattern ( id , parent_id , some_data ) Question: How to get leaves for given node_id? Table structure: CREATE TABLE `DATA_TREE` ( `ID` int(11) NOT NULL, `PARENT_ID` int(11) NOT NULL, `DATA` varchar(45) DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`), KEY `fk_DATA_TREE_1_idx` (`PARENT_ID`), CONSTRAINT `fk_DATA_TREE_1` FOREIGN KEY (`PARENT_ID`) REFERENCES `DATA_TREE` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf

@ Symbol - a solution for Recursive SELECT query in Mysql?

徘徊边缘 提交于 2019-11-27 14:33:20
there are a lot of questions about Recursive SELECT query in Mysql, but most of answers is that "There NO solution for Recursive SELECT query in Mysql". Actually there is a certain solution & I want to know it clearly, so this question is the following of the previous question that can be found at ( how-to-do-the-recursive-select-query-in-mysql ) Suppose you have this table: col1 - col2 - col3 1 - a - 5 5 - d - 3 3 - k - 7 6 - o - 2 2 - 0 - 8 & you want to find all the links that connect to value "1" in col1, i.e. you want to print out: 1 - a - 5 5 - d - 3 3 - k - 7 Then you can use this

MySQL: How to find leaves in specific node

冷暖自知 提交于 2019-11-27 03:47:29
问题 I know this kind questions has been posted here many times, for exmaple: Java way I have huge amount of data (150k+) in standard tree pattern ( id , parent_id , some_data ) Question: How to get leaves for given node_id? Table structure: CREATE TABLE `DATA_TREE` ( `ID` int(11) NOT NULL, `PARENT_ID` int(11) NOT NULL, `DATA` varchar(45) DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`), KEY `fk_DATA_TREE_1_idx` (`PARENT_ID`), CONSTRAINT `fk_DATA_TREE_1` FOREIGN KEY (`PARENT_ID`)

@ Symbol - a solution for Recursive SELECT query in Mysql?

半城伤御伤魂 提交于 2019-11-26 16:48:19
问题 there are a lot of questions about Recursive SELECT query in Mysql, but most of answers is that "There NO solution for Recursive SELECT query in Mysql". Actually there is a certain solution & I want to know it clearly, so this question is the following of the previous question that can be found at (how-to-do-the-recursive-select-query-in-mysql) Suppose you have this table: col1 - col2 - col3 1 - a - 5 5 - d - 3 3 - k - 7 6 - o - 2 2 - 0 - 8 & you want to find all the links that connect to

How to delete large data of table in SQL without log?

≯℡__Kan透↙ 提交于 2019-11-26 15:06:35
I have a large data table. There are 10 million records in this table. What is the best way for this query Delete LargeTable where readTime < dateadd(MONTH,-7,GETDATE()) If you are Deleting All the rows in that table the simplest option is to Truncate table, something like TRUNCATE TABLE LargeTable GO Truncate table will simply empty the table, you cannot use WHERE clause to limit the rows being deleted and no triggers will be fired. On the other hand if you are deleting more than 80-90 Percent of the data, say if you have total of 11 Million rows and you want to delete 10 million another way