Skip to content

Instantly share code, notes, and snippets.

View songyunlu's full-sized avatar

Jimmy Lu songyunlu

View GitHub Profile
SELECT * FROM opp WHERE phone = '1234567' or cellPhone = '7654321';
/* 改寫為 */
SELECT * FROM opp WHERE phone = '1234567'
UNION
SELECT * FROM opp WHERE cellPhone = '7654321';
@songyunlu
songyunlu / IN.sql
Last active December 14, 2015 08:19
SELECT * FROM opp WHERE phone = '1234567'or phone = '7654321';
/* 改寫為 */
SELECT * FROM opp WHERE phone IN('1234567', '7654321');
/* 欄位定義:`remark` varchar(50) NOT NULL */
/* 執行時間:0.14 秒 */
SELECT `id`, `gift_code` FROM gift WHERE `deal_id` = 640 AND remark = 115127;
/* 執行時間:0.005 秒 */
SELECT `id`, `gift_code` FROM gift WHERE `deal_id` = 640 AND remark = '15127';
/* 執行時間:2.19 秒 */
SELECT phone, COUNT(*) from post GROUP BY phone LIMIT 1;
/* 執行時間:2.02秒 */
SELECT phone, COUNT(*) from post GROUP BY phone ORDER BY NULL LIMIT 1;
SELECT * FROM table WHERE id >= 23423 LIMIT 11;
/* 10 + 1 每頁十筆資料 */
SELECT * FROM table WHERE id >= 23433 LIMIT 11;
UPDATE post SET tag = 1 WHERE id IN (1,2,3);
sleep 0.01;
UPDATE post SET tag = 1 WHERE id IN (4,5,6);
sleep 0.01;
......
SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
/* 可能引起同步的延遲,還可能導致同步出錯,特別是有設定 AUTO_INCREMENT 時 */
INSERT INTO table1 (SELECT * FROM table2);
package servletutils;
import com.google.common.base.Preconditions;
import javax.servlet.*;
import javax.servlet.http.*;
public class UnhandledExceptionFilter implements Filter {
public interface ErrorHandler {
void handle(HttpServletRequest request, HttpServletResponse response, Throwable throwable);
package demo;
import java.util.Arrays;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.catalina.LifecycleListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@songyunlu
songyunlu / CassandraEnvironmentRepository.java
Last active August 29, 2015 14:13
Spring Cloud Config CassandraEnvironmentRepository
public class CassandraEnvironmentRepository implements EnvironmentRepository {
private static final Logger logger = Logger.getLogger(CassandraEnvironmentRepository.class);
@Autowired
private PropertiesRepository propertiesRepository;
@Override
public Environment findOne(final String application, final String profile, final String label) {
Environment result = new Environment(profile, label);