파티셔닝 Partitioning

mysql 2018.12.17 14:51


create table BusinessCard

(id int not null, name varchar(255), address varchar(255), telephone varchar(255), createtime date)

  partition by range(year(createtime))(

  partition p0 values less than (2013),

  partition p1 values less than (2014),

  partition p2 values less than (2015),

  partition p3 values less than MAXVALUE

);


show create table BusinessCard\G


insert into BusinessCard values (1, 'kim','seoul',' 123-456', '2000-01-01');

insert into BusinessCard values (2, 'lee','seoul',' 123-456', '2014-01-01');


explain partitions select * from BusinessCard where createtime >= '2014-01-01' \G


파티션 추가/삭제

alter table BusinessCard add partition(

   partition p4 values less than (2005));


alter table BusinessCard drop partition p4;


파티션 분할/병합

alter table BusinessCard

 reorganize partition p3 into (

 partition p3 values less than(2015), 

 partition p4 values less than MAXVALUE

);


alter table BusinessCard

 reorganize partition p2, p3 into (

 partition p23 values less than (2014));




Trackbacks 0 : Comments 0

mysql dbdriver call store procedure in codeigniter(ci)

php 2018.12.17 14:19

mysql dbdriver call store procedure in codeigniter(ci)




<!-- php -->


$sql = "CALL .sp(@out1);";


$this->db->query($sql);            


$query = $this->db->query("SELECT @out1");




$result_temp = array();




if($query->num_rows() > 0)


$result_temp = $query->result_array();








<!-- mysql -->


CREATE DEFINER=`id`@`ip` PROCEDURE `sp`( 


OUT `last_id` INT


)


BEGIN




SET last_id = "test";




END$$




DELIMITER ;






<!-- codeigniter system/database/DB_active_rec.php -->




/**


* "Count All Results" query


*


* Generates a platform-specific query string that counts all records


* returned by an Active Record query.


*


* @param string


* @return string


*/


public function count_all_results($table = '')


{


if ($table != '')


{


$this->_track_aliases($table);


$this->from($table);


}




$sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));




$query = $this->query($sql);


 


$result_temp = $query->result();




$array_temp = json_decode(json_encode($result_temp[0]), True);




$this->_reset_select();




if ($array_temp["numrows"] == 0)


{


return 0;


}




return (int) $array_temp["numrows"];


}



Trackbacks 0 : Comments 0

Golang : Set up source IP address before making HTTP request

분류없음 2017.08.29 17:15


[출처] https://www.socketloop.com/tutorials/golang-set-up-source-ip-address-before-making-http-request


Problem :

There are times that you want to use certain IP address in a machine ( such as the one with permission to connect outside a firewall ) before making a HTTP request to another server. This is similar to the wget binding command :

For example : wget --bind-address=192.168.10.1 \

How to do that in Golang?

NOTE : This is not for masking or spoofing your IP address

Solution :

Build your own custom HTTP transport client and specify the local IP address that has the permission to connect outside a firewall.

For example :

 package main

 import (
         "fmt"
         "io/ioutil"
         "net"
         "net/http"
         "os"
         "time"
 )

 func main() {
         OKAddr := "<change here>" // local IP address to use

         OKAddress, _ := net.ResolveTCPAddr("tcp", OKAddr)

         transport := &http.Transport{
                 Proxy: http.ProxyFromEnvironment,
                 Dial: (&net.Dialer{
                         Timeout:   30 * time.Second,
                         KeepAlive: 30 * time.Second,
                         OKAddr: OKAddress}).Dial, TLSHandshakeTimeout: 10 * time.Second}

         client := &http.Client{
                 Transport: transport,
         }

         resp, err := client.Get("http://example.com/filetodown.zip")

         if err != nil {
                 panic(err)
         }

         defer resp.Body.Close()

         html, err := ioutil.ReadAll(resp.Body)

         if err != nil {
                 panic(err)
         }

         // fmt.Println(os.Stdout, string(html))
         // or save the zip - see https://www.socketloop.com/tutorials/golang-download-file-example
 }

References :

https://www.socketloop.com/tutorials/golang-convert-http-response-body-to-string

https://www.socketloop.com/tutorials/golang-download-file-example


Trackbacks 0 : Comments 0