Mysql高级进阶笔记

Mysql高级进阶

降序:desc

SELECT *  FROM `user` ORDER  BY `user`.id DESC

默认为升序

数据库分页

SELECT *  FROM `user` LIMIT 0,5

0 代表偏移量 5代表个数
公式 ((page-1)*pagesize,pagesize)

Mybatis-plus分页查询插件
current 第几页 size几条

@RequestMapping("/limit")
    public Resopnse limit(Integer current,Integer size){
    Resopnse resopnse=new Resopnse();
        Page<Online> userPage=new Page<>(current,size);
        resopnse.setData( onlineDao.selectPage(userPage,null));
//        System.out.println(userPage.getRecords());//list集合
//        System.out.println(userPage.getTotal());//总条数
//        System.out.println(userPage.getSize());//每页数
//        System.out.println(userPage.getPages());//总页数
//        System.out.println(userPage.hasNext());//下一页
//        System.out.println(userPage.hasPrevious());//上一页
        return  resopnse;
    }

性能下降sql慢的原因

1.查询语句问题
2.索引失效 单值 复合
3.关联查询太多join
4.服务器调优及各个参数设置 缓冲 线程数等。

七大join

1.包含Mysql高级进阶笔记_第1张图片
2.左关联
Mysql高级进阶笔记_第2张图片
3.右关联
Mysql高级进阶笔记_第3张图片
4.A独有
Mysql高级进阶笔记_第4张图片
5.全部

SELECT
	* 
FROM
	`user` u
	LEFT
	JOIN company c ON u.cid = c.id
	UNION
	SELECT
	* 
FROM
	`user` u
	RIGHT
	JOIN company c ON u.cid = c.id
	

Mysql高级进阶笔记_第5张图片6.各自独有

SELECT
	* 
FROM
	`user` u
	LEFT
	JOIN company c ON u.cid = c.id
	WHERE c.id IS NULL
	UNION
	SELECT
	* 
FROM
	`user` u
	RIGHT
	JOIN company c ON u.cid = c.id
	WHERE u.cid IS NULL

Mysql高级进阶笔记_第6张图片
7.b独有
Mysql高级进阶笔记_第7张图片

二.什么是索引

排好序的快速查找数据结构

索引就是数据结果
使用索引的目的
Mysql高级进阶笔记_第8张图片
索引
在这里插入图片描述
索引分类
Mysql高级进阶笔记_第9张图片

你可能感兴趣的:(mysql,mybatis,数据库)