自己的mac book pro
在升级到macOS Mojave(10.14)
之后,无法识别USB 3.0
有线网卡。
使用如下命令,查询网卡的设备类型:
1 |
$ system_profiler SPUSBDataType |
然后下载驱动安装才可以。
官方下载地址:
AX88179 Drivers Download
自己的mac book pro
在升级到macOS Mojave(10.14)
之后,无法识别USB 3.0
有线网卡。
使用如下命令,查询网卡的设备类型:
1 |
$ system_profiler SPUSBDataType |
然后下载驱动安装才可以。
官方下载地址:
AX88179 Drivers Download
背景
项目中,遇到一个统计需求,从某张表中按照条件分别统计。刚开始想到用union all的写法,太臃肿,后来使用count(distinct case when)解决此问题
count
数据统计中,count出现最频繁
最简单的用法
select count(*) from table where ....
select count(distinct xx) from table where ...
但最简单的用法也有其深刻的地方,比如这里其实有3种写法,count(1)、count(*)、count(字段),它们有什么区别呢?
count(1)和count(*)差别不大,使用count(*)时,sql会帮你自动优化,指定到最快的字段。所以推荐使用count(*)
count(*)会统计所有行数,count(字段)不会统计null值
count(case when)
条件统计,即对某个table分条件统计,比如表test_db,有一个字段user_id(可能重复), gender(man、women),需要统计man和women的人数
可以使用where分别统计
select count(distinct user_id) as man_cnt from test_db where gender = 'man'
select count(distinct user_id) as women_cnt from test_db where gender = 'women'
也可以使用按条件统计
select count(distinct case gender = 'man' then user_id end) as man_cnt
, count(distinct case gender = 'women' then user_id end) as woman_cnt
from test_db
最近在参照 树莓派实时系统下脚本语言的选择(应当使用Lua而不是Python) 调用调试lua-zmq
的时候,发现使用PAIR
模式进行线程之间通信,长时间运行后会出现死锁的情况。
当我们需要跟踪问题的时候,使用apt-get
安装的版本缺乏必要的调试信息。
我们可以手工安装调试信息包,如下:
1 2 3 4 5 6 7 8 9 10 |
$ sudo apt install libzmq-dbg # 系统默认的lua 5.1的符号信息使用如下命令安装 $ sudo apt-get install liblua5.1-0-dbg # libreadline提供了多个版本(5,6,7),根据需要下载对应的版本 $ sudo apt-get install libreadline6-dbg # sudo apt-get install search libtinfo* 根据返回的结果安装 $ sudo apt-get install libtinfo5-dbg |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 打开源代码的源 $ sudo sed -i "s/^#deb-src/deb-src/g" /etc/apt/sources.list # 安装必要的编译工具 $ sudo apt-get install build-essential devscripts lintian $ cd ~ # 下载源代码,此处不可sudo,否则后续操作会出现权限问题 $ apt-get source libzmq-dev $ cd zeromq*/ # 安装依赖项 $ sudo apt-get install libpgm-dev $ sudo apt-get install uuid-dev $ debuild -us -uc -b $ cd .. $ sudo dpkg -i libzmq-dev*.deb $ sudo dpkg -i libzmq-dbg*.deb $ sudo ldconfig |
Debian
安装包来进行的处理,然而对于luarocks
安装的插件来说,默认luarocks
是不能编译调试版本的,此时就需要我们手工编译了。我们以lua-zmq
为例子,参考如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ sudo apt-get -y install cmake $ git clone git://github.com/Neopallium/lua-zmq.git $ git checkout v1.1 $ cd lua-zmq ; mkdir build ; cd build $ cmake -DCMAKE_BUILD_TYPE=Debug .. $ make $ sudo make install $ sudo ldconfig |
背景
sql中表示不等于关系时,有两种写法!=、<>,抱着刨根问底的精神,看看这两个符号到底有什么不同
标准答案
https://stackoverflow.com/questions/18015422/what-is-difference-between-and-in-sql-server
搬运过来
这两个符号没有任何区别,你使用哪个都一样。
Microsoft的文档中,这两个符号的意义相同,都是 Not Equal To
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/not-equal-to-transact-sql-exclamation?view=sql-server-2017
但,<>是ANSI 99 SQL标准中的定义,!=不是。所以,不是所有的DB引擎都支持!=。
最终推荐使用<>。
背景
项目使用mysql数据库,某张表数据量2000W左右,比较大,在组合查询时发生超时,需要优化。
优化
查询优化常用方法就是建立索引
查询语句样例:查询在20181001-20181010时间范围内A=a且B=b的数据
select * from table where A = 'a' and B = 'b' and Date > '20181001' and Date < '20181010'
按照查询建立了一个组合索引 idx_query(A, B, Date),查询仍然报超时。然后开始研究索引原理,最后更改索引中列的顺序为idx_query(B,A,Date)解决。
---------------------------------------------------------------------------------------------
上面只是简单的项目背景,下面从原理细细解读索引
索引原理
首先,出问题以后再建立索引,是一种不好的习惯。排查、定位、解决问题会耗费很多开发时间和精力。
当然,不充分思考就给大多数列建立单列索引,给所有查询建立联合索引,是一种更坏的习惯。毕竟删除索引风险远高于添加索引。
使用索引需要成本:
索引适合在返回大表中很小一部分数据时使用,很小当然越小越好,5%以下还可以,1%以下更好,如果表的数据量非常大,千万级别,返回行数要小到0.1%以下
从很大表中用联合条件查询出很小的数据,等价于count(distinct 联合条件) 的值很大,这个值被称为Cardinality,索引适合度=Cardinality/表记录数。
索引误区
多个单列索引(如idx_A, idx_B)不等同于联合索引(idx_A_B)
两个联合索引里的列顺序不同,这两个联合索引也不等价,适用场景不同
联合索引idx_A_B能够覆盖的场景
覆盖场景可以根据索引存储结构(B+Tree)推导出。
上面罗列的几种覆盖场景,效率由上至下越来越低,因为扫描行数越来越大
联合条件中,最左侧的索引列很重要,最好使用Cardinality最大的列。
总结
项目中遇到的问题,最终根据索引原理中 最左侧索引列使用Cardinality最大列 解决。
在树莓派实时系统下脚本语言的选择(应当使用Lua而不是Python)中,我们没有使用rpi-gpio,而是使用了lua-periphery来解决Lua
语言下操作树莓派GPIO
的问题。
当时选择lua-periphery的原因在于rpi-gpio在Raspberry PI Zero W
中使用的时候会崩溃。这个原因是在于cpuinfo.c这个文件中缺少对于BCM2835
这颗新的CPU
的判断,只判断了BCM2708
(估计写这个库的时候,只有BCM2708
)。导致RPi_GPIO_Lua_module.c在初始化GPIO
的时候抛出了异常。这个已经有人提交了代码合并请求,估计很快会修复。
但是在lua-periphery中,没有对于GPIO
进行重新映射,导致跟rpi-gpio以及树莓派自带的Python
库在设置GPIO
的时候,端口号对应不一致。比如,在Python
中设置GPIO 22
,执行命令观察ls /sys/class/gpio/
,会发现系统创建的是GPIO 25
这个对应关系就是通过查表获取的。如下图:
继续阅读解决Raspberry PI Zero W中Lua使用lua-periphery与Python中设置的GPIO端口不一致的问题
最近在树莓派上需要安装libgtk2.0-dev
,执行如下命令:
1 |
$ sudo apt-get install libgtk2.0-dev |
出错信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: libgtk2.0-dev : Depends: libpango1.0-dev (>= 1.20) but it is not going to be installed Depends: libcairo2-dev (>= 1.6.4-6.1) but it is not going to be installed E: Unable to correct problems, you have held broken packages. |
根据出错信息,明显是软件源中出现了安装包缺失的问题。这个现象是不应该出现的。网上查询了不少地方,最终找到解决方法:
1 |
$ sudo vim /etc/apt/sources.list.d/raspi.list |
可以看到如下内容:
1 2 3 |
#deb http://archive.raspberrypi.org/debian/ stretch main ui staging # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://archive.raspberrypi.org/debian/ stretch main ui |
默认里面的内容都是被注释掉的,我们需要做的就是把这个源打开即可。
也可以直接执行如下命令来开启:
1 2 3 4 |
#先备份配置文件 $ sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak $ sudo sed -i "s/^\#deb/deb/g" /etc/apt/sources.list.d/raspi.list |
最近自己电脑上的ubuntu 18.04
在更新软件的时候报告如下错误信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ sudo apt upgrade 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 正在计算更新... 完成 下列软件包将被升级: libc6-armhf-cross libc6-dev-armhf-cross 升级了 2 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。 需要下载 0 B/2,904 kB 的归档。 解压缩后会消耗 0 B 的额外空间。 您希望继续执行吗? [Y/n] (正在读取数据库 ... 系统当前共安装有 239272 个文件和目录。) 正准备解包 .../libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb ... 正在将 libc6-dev-armhf-cross (2.27-3ubuntu1cross1.1) 解包到 (2.27-3ubuntu1cross1) 上 ... dpkg: 处理归档 /var/cache/apt/archives/libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb (--unpack)时出错: 无法打开 /usr/arm-linux-gnueabihf/lib/Mcrt1.o.dpkg-new : 没有那个文件或目录 错误信息显示本地系统有一些问题,因此没有写入 apport 报告 正准备解包 .../libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb ... 正在将 libc6-armhf-cross (2.27-3ubuntu1cross1.1) 解包到 (2.27-3ubuntu1cross1) 上 ... dpkg: 处理归档 /var/cache/apt/archives/libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb (--unpack)时出错: 无法打开 /usr/arm-linux-gnueabihf/lib/ld-2.27.so.dpkg-new : 没有那个文件或目录 错误信息显示本地系统有一些问题,因此没有写入 apport 报告 在处理时有错误发生: /var/cache/apt/archives/libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb /var/cache/apt/archives/libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb E: Sub-process /usr/bin/dpkg returned an error code (1) |
如果系统语言为英文,则错误信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$ sudo apt upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: libc6-armhf-cross libc6-dev-armhf-cross 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/2,904 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] (Reading database ... 239272 files and directories currently installed.) Preparing to unpack .../libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb ... Unpacking libc6-dev-armhf-cross (2.27-3ubuntu1cross1.1) over (2.27-3ubuntu1cross1) ... dpkg: error processing archive /var/cache/apt/archives/libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb (--unpack): unable to open '/usr/arm-linux-gnueabihf/lib/Mcrt1.o.dpkg-new': No such file or directory No apport report written because the error message indicates an issue on the local system Preparing to unpack .../libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb ... Unpacking libc6-armhf-cross (2.27-3ubuntu1cross1.1) over (2.27-3ubuntu1cross1) ... dpkg: error processing archive /var/cache/apt/archives/libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb (--unpack): unable to open '/usr/arm-linux-gnueabihf/lib/ld-2.27.so.dpkg-new': No such file or directory No apport report written because the error message indicates an issue on the local system Errors were encountered while processing: /var/cache/apt/archives/libc6-dev-armhf-cross_2.27-3ubuntu1cross1.1_all.deb /var/cache/apt/archives/libc6-armhf-cross_2.27-3ubuntu1cross1.1_all.deb E: Sub-process /usr/bin/dpkg returned an error code (1) |
解决方法为卸载后重新安装,而不使用升级安装:
1 2 3 |
$ sudo apt remove libc6-dev-armhf-cross $ sudo apt install libc6-dev-armhf-cross |
How do I fix an error with libc6-dev-armhf-cross in Ubuntu 18.04 when trying to apt upgrade?